[英]Log4j.properties does not producing logs with timestamp for LOGGER.info(), LOGGER.error() statements
I have recently added Log4j in my project and all the logs are printing as expected.我最近在我的项目中添加了 Log4j 并且所有日志都按预期打印。
Now I have added the timestamp in the log4j.properties file and server-generated logs are printing with the timestamp but which statements I am printing from Logger.info() and Logger.error() it is not printing with the timestamp.现在我已经在 log4j.properties 文件中添加了时间戳,并且服务器生成的日志正在使用时间戳打印,但是我从 Logger.info() 和 Logger.error() 打印的哪些语句没有使用时间戳打印。 This is how my log4j.properties look like:
这就是我的 log4j.properties 的样子:
logFileLoc = ${catalina.base}/logs/
log4j.rootLogger=INFO, stdout, fileAppender
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}: [%-5p] %c{1}:%L - %m%n
# Redirect Log Messages To A Debug Log File, Support File Rolling !!
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File=${logFileLoc}/catalina.out
log4j.appender.fileAppender.MaxFileSize=50MB
log4j.appender.fileAppender.MaxBackupIndex=10
log4j.appender.fileAppender.Append=true
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}: [%-5p] %c{1}:%L - %m%n
Whenever I try something like this in my code:每当我在我的代码中尝试这样的事情时:
LOGGER.debug("creating HomePage");
This is what I see in my log file:这是我在日志文件中看到的:
creating HomePage
Can anyone please suggest how can I print the timestamp in LOGGER statements?谁能建议我如何在 LOGGER 语句中打印时间戳? It will be highly appreciable.
这将是非常可观的。
I checked your configuration with log4j 1.2.17
and everything works correctly.我使用
log4j 1.2.17
检查了您的配置,一切正常。
I think you have other log4j config file in classpath or you are using system variables(like log4j.defaultInitOverride
or some others) which have impact on log4j configuration.我认为您在类路径中有其他 log4j 配置文件,或者您正在使用对 log4j 配置有影响的系统变量(如
log4j.defaultInitOverride
或其他一些)。 I recommend debugging log4j
initialization in static block of the LogManager
class and then you will see from which place log4j
is loading configuration.我建议在
LogManager
class 的 static 块中调试log4j
初始化,然后你会看到log4j
从哪个地方加载配置。
if I'm wrong, please provide code for reproducing your issue.如果我错了,请提供重现问题的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.