首页 \ 问答 \ 如何使用log4j2以编程方式禁用netty日志(How to disable netty logs programmatically using log4j2)

如何使用log4j2以编程方式禁用netty日志(How to disable netty logs programmatically using log4j2)

如何使用log4j2以编程方式禁用netty日志,同时使用来自ning.com的AsyncHttpClient libraray.I已经尝试了下面的代码但不工作。

我已经尝试了下面的代码

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

How to disable netty logs programmatically using log4j2 while using AsyncHttpClient from ning.com libraray.I have tried below code but not working.

I have tried below code

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

原文:https://stackoverflow.com/questions/43471506
更新时间:2020-01-18 08:37

最满意答案

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

    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();

It looks like you're just trying to change the log level of a particular logger. If that is what you need to do you can use code like this:

    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();

相关问答

更多

相关文章

更多

最新问答

更多
  • 在可观察字段Knocout中显示$符号(Display $ sign in observable fields Knocout)
  • 全局和设备功能之间的差异(Difference between global and device functions)
  • ARM,MCU,DSP,FPGA,SOC各是什么?区别是什么
  • Facebook JavaScript SDK登录(Facebook JavaScript SDK Login)
  • 会计实操有没有用,北京哪家会计培训最好?
  • 字段列表错误中的MySQL未知列(MySQL Unknown column in fieldlist error)
  • 在DOM深层获取评论节点(Get comment nodes in DOM deep level)
  • 2015年的会计上岗证培训那里好,在西安
  • 将long lat转换为google maps long lat(converting long lat to google maps long lat)
  • XSD xs:列表混乱(XSD xs:list confusion)
  • 在Wordpress中,有没有办法让导航下拉菜单显示一个类别中的帖子?(In Wordpress, is there a way to make the navigation drop down menu show posts in a category?)
  • 当我想清空名为python的列表时,del a [:]和a = []之间有什么区别?(what is the difference between del a[:] and a = [] when I want to empty a list called a in python? [duplicate])
  • 我的第一个项目入门与设备之间的连接(Getting started with my first project with connectivity between devices)
  • azure site-to-site-vpn不允许流量通过(azure site-to-site-vpn does not let traffic through)
  • GoogleMaps - 调用onPause()(GoogleMaps - calling onPause())
  • 教师爱岗敬业演讲稿
  • 我正在编写c#代码,其中我想从Active Directory中搜索特定用户的详细信息(I am writing c# code wherein I want search for the details of a specific user from Active Directory)
  • sonar lint插件无法读取lint-results.xml(sonar lint plugin fails reading lint-results.xml)
  • Swift UITableView - 如何将新项目置于列表底部而不是列表的底部?(Swift UITableView - How to put new items on top not on the bottom of the list?)
  • 无法将“System.DBNull”类型的对象强制转换为MySQL Image的“System.Byte []”类型[复制](Unable to cast object of type 'System.DBNull' to type 'System.Byte[]' for MySQL Image [duplicate])
  • 在这种情况下我为Android登录RESTful api调整了什么?(What i adjust for android login into RESTful api in this conditions?)
  • 使用DBMS的C#VSTO(C# VSTO with DBMS)
  • 在NSTableView中更改自定义按钮单元格的图像(Change image of custom button cell inside NSTableView)
  • 从数据库中选择数据,选择任何行(select data from database with where selected any rows)
  • 与Grails持续集成(Continuous Integration with Grails [closed])
  • Laravel 4中的嵌套控制器(Nested Controllers in Laravel 4)
  • Qt - 插槽完成后不要销毁线程(Qt - don't destroy thread after slot is finished)
  • mysql 主从配置 需要什么网络环境
  • Spring 4可选> @RequestParam(Spring 4 Optional> @RequestParam)
  • 移动类型char,类似的赋值行为不同(Shifting a type char, similar assignments behave differently)