如何在 log4j2 属性中的 class 上设置日志级别
How to set the log level on a class in log4j2 properties
在 log4j 中,我可以在属性文件中指定 class 以在调试级别记录,如下所示:
log4j.logger.com.mycompany.mypackage.ClassName=DEBUG
如何在 log4j2 中执行此操作?请注意,我仍然需要使用新的 属性 文件(不是 xml 或 json)。
TIA
如log4j2 configuration documentation所述
As of version 2.4, Log4j now supports configuration via properties
files. Note that the property syntax is NOT the same as the syntax
used in Log4j 1.
然后它为所有类型的配置元素提供了一个实质性的例子。
关于您的问题,您需要在 loggers
元素中指定您的记录器,然后配置它们中的每一个。例如
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.
If a test file cannot be located the properties ConfigurationFactory
will look for log4j2.properties
on the classpath.
但您也可以自己配置位置。您可以使用系统 属性
-Dlog4j.configurationFile=conf/log4j.properties
具有适当的路径。
在 log4j 中,我可以在属性文件中指定 class 以在调试级别记录,如下所示:
log4j.logger.com.mycompany.mypackage.ClassName=DEBUG
如何在 log4j2 中执行此操作?请注意,我仍然需要使用新的 属性 文件(不是 xml 或 json)。
TIA
如log4j2 configuration documentation所述
As of version 2.4, Log4j now supports configuration via properties files. Note that the property syntax is NOT the same as the syntax used in Log4j 1.
然后它为所有类型的配置元素提供了一个实质性的例子。
关于您的问题,您需要在 loggers
元素中指定您的记录器,然后配置它们中的每一个。例如
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.
If a test file cannot be located the properties ConfigurationFactory will look for
log4j2.properties
on the classpath.
但您也可以自己配置位置。您可以使用系统 属性
-Dlog4j.configurationFile=conf/log4j.properties
具有适当的路径。