Create new log file daily using log4j
Asked Answered
C

1

11

I want to use Log4j in my java project, which configuration should I provide in configuration file that every night at 12.00 am new file will generate and file name should like - output-log-of-MyProjectName-HostName-2013-Dec-10.txt name). My configuration file is like that-

log4j.appender.FILE = org.apache.log4j.DailyRollingFileAppender    
log4j.appender.FILE.File = ${log}/log.out    
log4j.appender.FILE.DatePattern = '.' yyyy-MM-dd-a

It is creating new file everyday but it appending date after file name. Please help me. Thanks in advance.

Compromise answered 16/12, 2013 at 18:50 Comment(5)
What exactly are you getting and how does it differ from what you want?Pinnacle
Can you give an example of the file nameS (more than one) you are seeing, and what you want them to look like?Schnurr
logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/…Langue
I just want my file name should start with current date, like output-log-2013-Dec-10.txt, Please help,Compromise
Log4J is appending date after its file name, so the extension of the file is changed, is it possible to append date before file extension. Generated file is logfile.out.2013-12-16-PM but I want like logfile.2013-12-16-PM.outCompromise
G
10

I think you want DailyRollingFileAppender (geedubb links to the log4j docs about it) Here is example

Here is another stackoverflow question like yours

Garland answered 16/12, 2013 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.