简体   繁体   中英

Migrating from log4j to log4j2 - properties file configuration including categories

I have a java application which is using log4j configured as below.

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1
log4j.debug=false

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c %x - %m%n
#log4j.appender.A1.threshold=DEBUG

# DEBUG, INFO, WARN, ERROR, FATAL
log4j.category.com.myorganization.MyClass=INFO
log4j.category.com.myorganization.MyOtherClass=WARN

I would like to migrate to log4j2 with the same configuration as above. While I have found lots of documentation, especially Migrating from log4j to log4j2 - properties file configuration none of the examples contain category configuration as I have it in the last two lines.

Please can anyone help me out how would be my log4j2.properties file with the same configuration above?

Thanks to Piotr's explanation, the solution to my question looks like this:

appenders=xyz

appender.xyz.type = Console
appender.xyz.name = myOutput
appender.xyz.layout.type = PatternLayout
appender.xyz.layout.pattern = [%d{yy-MMM-dd HH:mm:ss:SSS}] [%p] [%c:%L] - %m%n

rootLogger.level = debug
rootLogger.appenderRefs = abc
rootLogger.appenderRef.abc.ref = myOutput

logger.c1.name=com.myorganization.MyClass
logger.c1.level=INFO
logger.c2.name=com.myorganization.MyOtherClass
logger.c2.level=WARN

The only drawback seems that the loggers now need to have names (c1, c2, whatever unique names).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM