0

My java app using log4j 1.2.17 to out log. this is my log4j.properties

log4j.rootLogger=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p 
%c{1}:%L - %m%n

log4j.appender.debugLog=sim.convert.log.RollingFileAppender
log4j.appender.debugLog.File=C:/log/batch01.log
log4j.appender.debugLog.layout=org.apache.log4j.PatternLayout
log4j.appender.debugLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n
log4j.appender.debugLog.MaxFileSize=10MB
log4j.appender.debugLog.encoding=UTF-8
log4j.appender.debugLog.MaxBackupIndex=2
log4j.appender.debugLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} 
%-5p %c{1}:%L - %m%n

it's will create back up file is batch01.log.1. But i need file name of back up is "batch_yyyy-MM-dd.log.1" How I can do that, please help me thank.

  • Possible duplicate of [Filename with date in Log4j](https://stackoverflow.com/questions/4629772/filename-with-date-in-log4j) – Niebian Feb 02 '18 at 09:51

2 Answers2

0

you can use the DailyRollingFileAppender instead of RollingFileAppender

log4j.appender.serverAccess=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.serverAccess=org.apache.log4j.RollingFileAppender
log4j.appender.serverAccess.DatePattern='.'yyyy-MM-dd
ryanlee
  • 341
  • 3
  • 9
0

Thank you so much guys. I was resolve my problem with create a java class CustomLog extend RollingFileAppender and override subAppend() function to check and change the backup file name