log4j2属性加载迁移
更新Log4 Jars后,我有一个问题要打印日志文件。这是我的实现。对于log4j的旧版本,我们仅对logf4.properties使用“ propertyConfigurator”(这是一个外部文件)。我不确定我是否错过了要声明的东西,但是在测试日志时仍未打印。 IM当前现在使用的Log4J版本是2.17.2
private LoggerConfig (){
try {
//PropertyConfigurator.configureAndWatch(Constants.LOG_CONFIG);
LoggerContext context = (LoggerContext) LogManager.getContext(false);
File file = new File(Constants.LOG_CONFIG);
ConfigurationSource source = new ConfigurationSource(new FileInputStream(Constants.LOG_CONFIG), new File(Constants.LOG_CONFIG));
Configurator.initialize(null, source);
LOGGER = LogManager.getLogger(this.getClass());
LoggerContext.getContext().setConfigLocation(file.toURI());
LOGGER.debug("Log4j Properties successfully loaded.");
} catch (Exception e) {
LOGGER.error("Unable to load application properties file: " + Constants.LOG_CONFIG);
}
LOGGER.debug("Connection pool successfully initialized.");
}
I'm having a problem to print the log files after updating the log4 jars. Here is my implementation below. for the old version of log4j we only use the "PropertyConfigurator" for our logf4.properties (this is an external file). Im not sure if I missed something to declare but upon testing logs still not printing. The log4j version that im currently using now is the 2.17.2
private LoggerConfig (){
try {
//PropertyConfigurator.configureAndWatch(Constants.LOG_CONFIG);
LoggerContext context = (LoggerContext) LogManager.getContext(false);
File file = new File(Constants.LOG_CONFIG);
ConfigurationSource source = new ConfigurationSource(new FileInputStream(Constants.LOG_CONFIG), new File(Constants.LOG_CONFIG));
Configurator.initialize(null, source);
LOGGER = LogManager.getLogger(this.getClass());
LoggerContext.getContext().setConfigLocation(file.toURI());
LOGGER.debug("Log4j Properties successfully loaded.");
} catch (Exception e) {
LOGGER.error("Unable to load application properties file: " + Constants.LOG_CONFIG);
}
LOGGER.debug("Connection pool successfully initialized.");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您主要使用logger.debug,将记录级别设置为调试还是更低?
如果设置为更高的级别
you are using mostly LOGGER.debug, the logging level is set to DEBUG or lower?
if is set to a higher level please consider setting it to a level lower to debug or trace to validate the logf4.properties is proper linked