How to generate log files with data log4j

Asked

Viewed 1,058 times

1

Good afternoon to all,

I am using log4j(log4j-1.2.17.jar) to generate the log of the system, however now I need to generate the log with date and make q it generates a log every day, I need the log to be generated so "testLog-20-05-2016.log" and tb need to do with q when turn day create a new log.

log4j.rootCategory=INFO,stdout,fileOut

log4j.category.fileOut=INFO

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout


log4j.appender.fileOut.layout.ConversionPattern=%d{dd-MM-yy HH:mm:ss,SSS} [%t] %5p %c:%L - %m%n
log4j.appender.fileOut =org.apache.log4j.RollingFileAppender
log4j.appender.fileOut.File=d://logTeste.log
log4j.appender.fileOut.layout=org.apache.log4j.PatternLayout

I have no idea how to put the date in the file name, someone can help me?

2 answers

0


to solve the problem I needed the jar "datedFileAppender-1.0.3.jar"

and the configuration was as follows:

log4j.rootCategory=INFO,stdout,fileOut

log4j.category.fileOut=INFO

log4j.appender.stdout=biz.minaret.log4j.DatedFileAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.fileOut=biz.minaret.log4j.DatedFileAppender
log4j.appender.fileOut.layout.ConversionPattern=%d{dd-MM-yy HH:mm:ss,SSS} [%t] %5p %c:%L - %m%n
log4j.appender.fileOut.Directory=d://
log4j.appender.fileOut.Prefix=arqLog-
log4j.appender.fileOut.append=true
log4j.appender.fileOut.layout=org.apache.log4j.PatternLayout

0

For documentation, you must use a RollingFileAppender like you did, using the property FilePattern in conjunction with File:

log4j.appender.fileOut.FilePattern=d://logTeste-%d{dd-MM-yyyy}.log

Browser other questions tagged

You are not signed in. Login or sign up in order to post.