根据log4j2 2.4版常见问题进行编辑
您可以使用Log4j Core中的Configurator类设置记录器的级别。 但是请 注意,Configurator类不是公共API的一部分。
// org.apache.logging.log4j.core.config.Configurator;Configurator.setLevel("com.example.Foo", Level.DEBUG);// You can also set the root logger:Configurator.setRootLevel(Level.DEBUG);资源
编辑以反映Log4j2 2.0.2版中引入的API中的更改
如果您希望更改根记录器级别,请执行以下操作:
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);Configuration config = ctx.getConfiguration();LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); loggerConfig.setLevel(level);ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig.
这是LoggerConfig的Javadoc。



