How to set the log level on a class in log4j2 properties

邮差的信 提交于 2019-12-03 23:43:09

As the log4j2 configuration documentation states

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.

It then provides a substantial example for all types of configuration elements.

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.

If a test file cannot be located the properties ConfigurationFactory will look for log4j2.properties on the classpath.

But you can also configure the location yourself. You can use the system property

-Dlog4j.configurationFile=conf/log4j.properties

with an appropriate path.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!