How to generate log files with data log4j

1

Good afternoon everyone,

I'm using log4j (log4j-1.2.17.jar) to generate the system log, but now I need to generate the log with data and cause it to generate a log every day, I need the log to be generated like this " testLog-20-05-2016.log "and you have to do with q when you turn the 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, can anyone help me?

    
asked by anonymous 20.05.2016 / 19:30

2 answers

0

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

and the setting is 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
    
27.05.2016 / 17:52
0

By documentation you should use RollingFileAppender as you did , using the FilePattern property in conjunction with File:

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