Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

java - Create new log file daily using log4j

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Here is another stackoverflow question like yours


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...