How to add the time stamp to the log file
ello Everyone, I am new to using apache logger . I have downloaded the log4j-xx and i have the following text configuration file Set root logger level to DEBUG and its only appender to mainFormat.
log4j.rootLogger = TRACE, mainFormat, FILE
mainFormat is set to be a ConsoleAppender.
log4j.appender.mainFormat=org.apache.log4j.ConsoleAppender
mainFormat uses PatternLayout.
log4j.appender.mainFormat.layout=org.apache.log4j.PatternLayout
log4j.appender.mainFormat.layout.ConversionPattern=%d [%t] %-开发者_开发百科5p %c - %m%n
File makes a file of the output.
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=log4j_HAPR001_OutputFile.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
i use the above config file to create the log file. Now i wanted to add the current time stamp to the log file. Is there any way to do this. If yes can some one please give me the instructions how to do. Thanks in advance.
To add a timestamp to the name of a logfile, use DailyRollingFileAppender
(see the docs how to configure it)
You can add the date to the pattern using this:
%utcdate{yyyy-MM-dd HH:mm:ss.fff}
To see it in context, here is a complete PatternLayout conversion pattern:
%utcdate{yyyy-MM-dd HH:mm:ss.fff} %-5level [%thread] - %type.%method - %message%newline
精彩评论