How to define DailyRollingFileAppender in Log4J.properties file


      Click here to attend Spring Framework 4.x and certification course with a discount

Spring Framework and Core Spring Certification Udemy course with discount
Spring Framework and Core Spring Certification Udemy course with a discount coupon

Use the following Log4j.properties file

# Set root category priority to INFO and its only appender to DailyRollingFileAppender.
log4j.rootCategory=INFO, LOGFILE

# Set the enterprise logger category to FATAL and its only appender to DailyRollingFileAppender.
log4j.logger.org.apache.axis.enterprise=FATAL, LOGFILE

#reFactor Tuna
# LOGFILE is set to be a DailyRollingFileAppender appender using a PatternLayout.
log4j.appender.LOGFILE = org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOGFILE.File=/log/logFileName.log
log4j.appender.LOGFILE.Append = true
log4j.appender.LOGFILE.Threshold=DEBUG
log4j.appender.LOGFILE.DatePattern = ‘.’yyy-MM-dd
log4j.appender.LOGFILE.layout = org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n

Advertisements

5 thoughts on “How to define DailyRollingFileAppender in Log4J.properties file

  1. Found error after use DailyRollingFileAppender. How to solve this issue?

    After roll (copied) to /foo/bar.log.yyyy-mm-dd, during the day found that system still log to normal log and also log into daily rolling file (xx.log.yyyy-mm-dd)
    Example

    1335542770 Jul 28 23:59 xx.log.2013-07-28 <– Correct
    8833837770 Jul 29 10:22 xx.log.2013-07-26 <– Wrong (Should not happen this line)
    2518627750 Jul 29 10:22 xx.log <– Normal log

  2. I have the similar error with the case above.
    Could you help?
    Here is my log4j.properties configuration:

    log4j.rootLogger=no, daily
    log4j.logger.ProcessLogger=debug, batch

    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %m%n

    log4j.appender.batch=org.apache.log4j.RollingFileAppender
    log4j.appender.batch.append=true
    log4j.appender.batch.File=xx.log
    log4j.appender.batch.MaxFileSize=2GB
    log4j.appender.batch.encoding=UTF-8
    log4j.appender.batch.layout=org.apache.log4j.PatternLayout
    log4j.appender.batch.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %m%n

    log4j.appender.daily=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.daily.file=/foo/bar.log
    log4j.appender.daily.datePattern=’.’yyyy-MM-dd
    log4j.appender.daily.append=true
    log4j.appender.daily.layout=org.apache.log4j.PatternLayout
    log4j.appender.daily.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %m%n

    Thanks in advance!

    1. Please try like this and let us know; replace all contents in log4j.properties with this one if you want to have only one logger for both loggers

      log4j.rootLogger=no, daily
      log4j.logger.ProcessLogger=debug, daily

      log4j.appender.stdout=org.apache.log4j.ConsoleAppender
      log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
      log4j.appender.stdout.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %m%n

      log4j.appender.daily=org.apache.log4j.DailyRollingFileAppender
      log4j.appender.daily.file=/foo/bar.log
      log4j.appender.daily.datePattern=’.’yyyy-MM-dd
      log4j.appender.daily.append=true
      log4j.appender.daily.layout=org.apache.log4j.PatternLayout
      log4j.appender.daily.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] %m%n

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s