Log4j2 replacement of PropertyConfigurator APIs configureAndWatch and configure
Viraj Jasani <[email protected]> Fri, 17 Mar 2023 20:59:26 -0700
| Newsgroups | gmane.comp.apache.logging.log4net.devel,gmane.comp.jakarta.log4j.user |
|---|---|
| Message-ID | <CAEY0_YpuRQVvcLsnqRT+USSLi0qNpxWa5DH_5Uh77C+O3UMm4g@mail.gmail.com> |
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);
}
}