Log4j使用属性文件为不同的日志级别使用不同的追加器 [英] Log4j different appenders for different log levels using properties file

查看:198
本文介绍了Log4j使用属性文件为不同的日志级别使用不同的追加器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于log4j的官方文档是损坏的链接,并且入门指南不是帮助我,我想知道如何使用两个追加器与不同的日志级别为同一个记录器,使用 .properties 文件而不是

 

code> log4j.rootLogger = debug,APPENDER_FILE,APPENDER_STDOUT

我使用两种不同的appenders,但在同一日志级别( DEBUG )。我想对 APPENDER_STDOUT 使用 INFO 日志级别,并为 DEBUG APPENDER_FILE 的日志级别。



我的问题类似于,但不同于那个问题,我使用 log4j.properties 文件,而不是xml文件。

解决方案

您需要将 logger 设置为两个级别(DEBUG)的更详细信息,然后在 appender 上设置一个阈值,告诉它只显示邮件在INFO及以上

  log4j.appender.APPENDER_STDOUT.Threshold = INFO 
pre>

Since the official documentation for log4j is a broken link, and the getting started guide isn't helping me, I would like to know how to use two appenders with different log levels for the same logger, using a .properties file instead of an .xml one.

For example, like this:

log4j.rootLogger=debug,  APPENDER_FILE, APPENDER_STDOUT

I'm logging with two different appenders, but on the same log level (DEBUG). I would like to use an INFO log level for APPENDER_STDOUT, and aDEBUG log level for APPENDER_FILE.

My question is similar to this, but unlike that question, I'm using the log4j.properties file, not the xml file.

解决方案

You need to set the logger to the more detailed of the two levels (DEBUG) but then set a threshold on the appender to tell it to only show messages at INFO and above

log4j.appender.APPENDER_STDOUT.Threshold=INFO

这篇关于Log4j使用属性文件为不同的日志级别使用不同的追加器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆