Hi,

Could you please help with log4j2 replacement for PropertyConfigurator APIs
configureAndWatch and configure?

For instance, this is the logic we have that we need to migrate to log4j2:



  protected void initLog() throws ServerException {
    verifyDir(logDir);
    LogManager.resetConfiguration();
    File log4jFile = new File(configDir, name + "-log4j.properties");
    if (log4jFile.exists()) {
      PropertyConfigurator.configureAndWatch(log4jFile.toString(), 10 *
1000); //every 10 secs
      log = LoggerFactory.getLogger(Server.class);
    } else {
      Properties props = new Properties();
      try {
        InputStream is = getResource(DEFAULT_LOG4J_PROPERTIES);
        try {
          props.load(is);
        } finally {
          is.close();
        }
      } catch (IOException ex) {
        throw new ServerException(ServerException.ERROR.S03,
DEFAULT_LOG4J_PROPERTIES, ex.getMessage(), ex);
      }
      PropertyConfigurator.configure(props);
      log = LoggerFactory.getLogger(Server.class);
      log.warn("Log4j [{}] configuration file not found, using default
configuration from classpath", log4jFile);
    }
  }

Reply via email to