从 log4j 迁移到 log4j2-properties 文件配置

发布于 2025-01-14 11:26:51 字数 3181 浏览 0 评论 0原文

我有一个 java webservices 项目代码,它使用 log4j 属性,如下所示。当我们调用某些 Web 服务时,它会打印到 tomcat 日志文件。

在参考跨站点的现有文档后,我创建了下面的 log4j2.properties 文件。然而它似乎不起作用。当我调用某些 Web 服务时,它根本不会像以前使用 log4j 那样打印到 tomcat 日志文件。我的项目没有使用Maven/Spring框架。

Log4j.properties

# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
#log4j.rootCategory=INFO, CONSOLE, LOGFILE

# Set the enterprise logger priority to FATAL
log4j.logger.org.apache.axis2.enterprise=FATAL
log4j.logger.de.hunsicker.jalopy.io=FATAL
log4j.logger.httpclient.wire.header=FATAL
log4j.logger.org.apache.commons.httpclient=FATAL

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%p: %d{MMM dd, yyyy h:mm:ss a} %C %M [%t]%n%m%n

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=axis2.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n

Log4j2.properties

#log4j.rootCategory=INFO, CONSOLE, LOGFILE
appenders=CONSOLE
rootlogger.level = INFO
status = ERROR

# Set the enterprise logger priority to FATAL
#log4j.logger.org.apache.axis2.enterprise=FATAL
#log4j.logger.de.hunsicker.jalopy.io=FATAL
#log4j.logger.httpclient.wire.header=FATAL
#log4j.logger.org.apache.commons.httpclient=FATAL

logger.enterprise.name = org.apache.axis2.enterprise
logger.enterprise.level = FATAL

logger.io.name = de.hunsicker.jalopy.io
logger.io.level = FATAL

logger.header.name = httpclient.wire.header
logger.header.level = FATAL

logger.httpclient.name = org.apache.commons.httpclient
logger.httpclient.level = FATAL

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
##log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
##log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
##log4j.appender.CONSOLE.layout.ConversionPattern=%p: %d{MMM dd, yyyy h:mm:ss a} %C %M [%t]%n%m%n
appender.CONSOLE.type = Console
appender.CONSOLE.name = STDOUT
appender.CONSOLE.layout.type = PatternLayout
appender.CONSOLE.layout.pattern = %p: %d{MMM dd, yyyy h:mm:ss a} %C %M [%t]%n%m%n

# LOGFILE is set to be a File appender using a PatternLayout.
##log4j.appender.LOGFILE=org.apache.log4j.FileAppender
##log4j.appender.LOGFILE.File=axis2.log
##log4j.appender.LOGFILE.Append=true
##log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
##log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n

# Log4j2 version for LOGFILE - Not sure if i should define this. Log4j.rootcategory in LOG4J Properties file does seem to define this.
#appender.LOGFILE.type = File
#appender.logfile.file = axis2.log
#appender.logfile.layout.type = PatternLayout
#appender.logfile.layout.pattern = %d [%t] %-5p %c %x - %m%n

rootLogger.appenderRef.stdout.ref = STDOUT

我是java新手。有人可以帮助验证 log4j2 属性文件是否需要更正/更新吗?

I have a java webservices project code which is using log4j properties as below. It prints to tomcat log file when we invoke certain webservice.

I created below log4j2.properties file after referring to existing documentation across sites. However it doesn't seem to be working. It is not at all printing to tomcat log file like it used to earlier with log4j when I invoke certain webservice. My project does not use Maven/Spring framework.

Log4j.properties

# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
#log4j.rootCategory=INFO, CONSOLE, LOGFILE

# Set the enterprise logger priority to FATAL
log4j.logger.org.apache.axis2.enterprise=FATAL
log4j.logger.de.hunsicker.jalopy.io=FATAL
log4j.logger.httpclient.wire.header=FATAL
log4j.logger.org.apache.commons.httpclient=FATAL

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%p: %d{MMM dd, yyyy h:mm:ss a} %C %M [%t]%n%m%n

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=axis2.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n

Log4j2.properties

#log4j.rootCategory=INFO, CONSOLE, LOGFILE
appenders=CONSOLE
rootlogger.level = INFO
status = ERROR

# Set the enterprise logger priority to FATAL
#log4j.logger.org.apache.axis2.enterprise=FATAL
#log4j.logger.de.hunsicker.jalopy.io=FATAL
#log4j.logger.httpclient.wire.header=FATAL
#log4j.logger.org.apache.commons.httpclient=FATAL

logger.enterprise.name = org.apache.axis2.enterprise
logger.enterprise.level = FATAL

logger.io.name = de.hunsicker.jalopy.io
logger.io.level = FATAL

logger.header.name = httpclient.wire.header
logger.header.level = FATAL

logger.httpclient.name = org.apache.commons.httpclient
logger.httpclient.level = FATAL

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
##log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
##log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
##log4j.appender.CONSOLE.layout.ConversionPattern=%p: %d{MMM dd, yyyy h:mm:ss a} %C %M [%t]%n%m%n
appender.CONSOLE.type = Console
appender.CONSOLE.name = STDOUT
appender.CONSOLE.layout.type = PatternLayout
appender.CONSOLE.layout.pattern = %p: %d{MMM dd, yyyy h:mm:ss a} %C %M [%t]%n%m%n

# LOGFILE is set to be a File appender using a PatternLayout.
##log4j.appender.LOGFILE=org.apache.log4j.FileAppender
##log4j.appender.LOGFILE.File=axis2.log
##log4j.appender.LOGFILE.Append=true
##log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
##log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n

# Log4j2 version for LOGFILE - Not sure if i should define this. Log4j.rootcategory in LOG4J Properties file does seem to define this.
#appender.LOGFILE.type = File
#appender.logfile.file = axis2.log
#appender.logfile.layout.type = PatternLayout
#appender.logfile.layout.pattern = %d [%t] %-5p %c %x - %m%n

rootLogger.appenderRef.stdout.ref = STDOUT

I am new to java. Can someone please help validate if log4j2 properties file needs corrections/updates?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文