问题描述
在log4j中我可以在属性文件中指定一个类来记录调试级别,如下所示:
in log4j I could specify a class in the properties file to log at the debug level like this:
log4j.logger.com.mycompany.mypackage.ClassName=DEBUG
如何在log4j2中执行此操作?注意我仍然需要使用新的属性文件(不是xml或json)。
How do I do this in log4j2? Note I still need to use the new property file (not xml or json).
TIA
推荐答案
作为 states
然后它为所有类型的配置元素提供了一个重要的例子。
It then provides a substantial example for all types of configuration elements.
关于您的问题,您需要在 loggers
元素中指定记录器,然后配置每个记录器。例如
Concerning your question, you need to specify your loggers in a loggers
element, then configure each of them. For example
loggers = mine
logger.mine.name = com.mycompany.mypackage.ClassName
logger.mine.level = DEBUG
Note that log4j2 looks for a .properties
file on the classpath by default.
但您也可以自己配置位置。您可以使用系统属性
But you can also configure the location yourself. You can use the system property
-Dlog4j.configurationFile=conf/log4j.properties
有适当的路径。
这篇关于如何在log4j2属性中设置类的日志级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!