如何使用log4j2以编程方式禁用netty日志

时间:2017-04-18 11:57:52

标签: java netty log4j2

如何在使用ning.com libraray的AsyncHttpClient时使用log4j2以编程方式禁用netty日志。我尝试过以下代码但不能正常工作。

我试过下面的代码

org.apache.logging.log4j.core.config.Configurator.setLevel(LogManager.getLogger("io.netty").getName(),org.apache.logging.log4j.Level.INFO);  

1 个答案:

答案 0 :(得分:0)

看起来您只是想尝试更改特定记录器的日志级别。如果这是你需要做的,你可以使用这样的代码:

    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerCfg = config.getLoggerConfig("io.netty");
    loggerCfg.setLevel(Level.OFF); //Using this level disables the logger.
    ctx.updateLoggers();