简体   繁体   English

从 log4j 迁移到 log4j2 - 包括类别的属性文件配置

[英]Migrating from log4j to log4j2 - properties file configuration including categories

I have a java application which is using log4j configured as below.我有一个 java 应用程序,它使用 log4j 配置如下。

# 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.我想用与上面相同的配置迁移到 log4j2。 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.虽然我找到了很多文档,特别是从 log4j 迁移到 log4j2 - 属性文件配置没有一个示例包含类别配置,因为我在最后两行中有它。

Please can anyone help me out how would be my log4j2.properties file with the same configuration above?请谁能帮我看看我的 log4j2.properties 文件与上面相同的配置如何?

Thanks to Piotr's explanation, the solution to my question looks like this:感谢 Piotr 的解释,我的问题的解决方案如下所示:

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).唯一的缺点似乎是记录器现在需要有名称(c1、c2、任何唯一名称)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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