[英]multiple log levels in same log file in log4j
How can multiple log levels added to the same log file in log4j? 如何将多个日志级别添加到log4j的同一日志文件中? For example: 例如:
log4j.rootLogger=INFO,WARN,stdout,file
It gives the log4j error when application start as: 当应用程序启动时,它给出log4j错误:
Could not instantiate appender named WARN.
The purpose of the threshold is to tell log4j to ignore all logging requests with a priority lower than what you specify. 阈值的目的是告诉log4j忽略优先级低于您指定的所有日志记录请求。 Specifying a given threshold does not limit you to logging with that threshold. 指定给定的阈值并不限制您使用该阈值进行记录。
FileAppender fa = new FileAppender();
fa.setThreshold(Level.INFO);
fa.setAppend(true);
Logger.getRootLogger().addAppender(fa);
In the above code, the appender has been configured to operate with a threshold of INFO
. 在上面的代码中,附加器已配置为以INFO
阈值进行操作。 This means that the following code will not log, because DEBUG
is a lower priority than INFO
: 这意味着以下代码将不会记录,因为DEBUG
的优先级低于INFO
:
Logger logger = Logger.getLogger(SomeClass.class);
logger.debug("This will not log");
But this code will log: 但是此代码将记录:
logger.warn("This debug message will log.");
logger.error("And this error message will also log.");
In this case, both WARN
and ERROR
have a higher priority than INFO
. 在这种情况下, WARN
和ERROR
的优先级都高于INFO
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.