Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 554
swati Avatar asked Nov 05 '22 14:11

swati


1 Answers

To add a timestamp to the name of a logfile, use DailyRollingFileAppender (see the docs how to configure it)

like image 194
Aaron Digulla Avatar answered Nov 15 '22 06:11

Aaron Digulla