log4j2中的BasicConfigurator替换 [英] BasicConfigurator replacement in log4j2
问题描述
我正在研究从log4j 1到log4j 2的迁移.在AppConfigInitializer文件中,我们使用类似以下内容-
I am working on a log4j 1 to log4j 2 migration. Inside a AppConfigInitializer file we use something like this -
BasicConfigurator.configure(consoleAppender);
要使它在log4j2中工作,我应将其替换为什么.我也使用了向后兼容桥,但是这破坏了BasicConfigurator的实现.
What shall I replace this with to get it working in log4j2. I am using the backward compatibility bridge as well but that has broken BasicConfigurator implementation.
我认为我需要使用配置文件来执行此操作,但无法找到方法.
I think I need to do this using config file, but not able to find how.
推荐答案
上述解决方案有效,但是由于默认日志级别为ERROR,因此不会显示所有日志.日志级别可以使用Configurator.setRootLevel方法进行调整:
The solution above works, but since default log level is ERROR, not all logs are shown. Log level can be adjusted with Configurator.setRootLevel method:
Configurator.initialize(new DefaultConfiguration());
Configurator.setRootLevel(Level.INFO);
这篇关于log4j2中的BasicConfigurator替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!