7 Replies Latest reply: Apr 10, 2007 10:54 AM by 807597 RSS

    log4j file appender

    807597
      Hi,

      I am using log4j for logging. I am working on a huge application and there would be lots of logs each day. Thereby it is requried that the log files be stored and renamed each day. The date is appended to the log file and that day's log file is stored. The logs start writing afresh each day. The problem here is that at times the application simply starts logging to the previous day's log file, for a while, and then starts writing back to the current day's file again. I am not able to figure out what goes wrong and when. The application is running on weblogic. Can anybody please help? The log4j properties file is here....


      # DO NOT MODIFY
      log4j.categoryFactory=com.myapp.util.logger.LoggerCategoryFactory
      log4j.rootCategory=INFO,DISABLED

      # EVENTS
      log4j.category.nmy.STATE=INFO,0,DAY,OBS
      log4j.category.nmy.EXCEPTION=DEBUG,10,DAY
      log4j.category.nmy.SESSION=INFO,0,DAY
      log4j.category.nmy.REQUEST=INFO,0,DAY
      log4j.category.nmy.MESSAGE=INFO,0,DAY
      log4j.category.nmy.OBJECT=INFO,0,DAY
      log4j.category.nmy.DATA=INFO,0,DAY
      log4j.category.nmy.NONE=DEBUG,5,DAY


      # DO NOT MODIFY
      log4j.appender.DISABLED=com.myapp.util.logger.NullAppender

      # STANDARD OUTPUT DRIVER SETTINGS
      log4j.appender.CON=org.apache.log4j.ConsoleAppender
      log4j.appender.CON.Target=System.out
      log4j.appender.CON.layout=com.myapp.util.logger.LoggerLayout
      log4j.appender.CON.layout.ConversionPattern=+{DATE_TIME};{EVENT_ID};{SESSION_ID};{SEVERITY};{MODULE};{THREAD_ID};{EVENT_TYPE};{ERROR_CODE};{DESCRIPTION};{DEBUG_INFO}

      # ROLLING FILE OUTPUT DRIVER SETTINGS
      log4j.appender.ROL=org.apache.log4j.RollingFileAppender
      log4j.appender.ROL.File=/var/opt/apps/myapp/var/logs/application.log
      log4j.appender.ROL.MaxFileSize=4000KB
      log4j.appender.ROL.MaxBackupIndex=5
      log4j.appender.ROL.layout=com.myapp.util.logger.LoggerLayout
      log4j.appender.ROL.layout.ConversionPattern=+{DATE_TIME};{EVENT_ID};{SESSION_ID};{SEVERITY};{MODULE};{THREAD_ID};{EVENT_TYPE};{ERROR_CODE};{DESCRIPTION};{DEBUG_INFO}

      # DAILY OUTPUT DRIVER SETTINGS
      log4j.appender.DAY=org.apache.log4j.DailyRollingFileAppender
      log4j.appender.DAY.File=/var/opt/apps/myapp/var/logs/daily_application.log
      log4j.appender.DAY.DatePattern='.'yyyy-MM-dd
      log4j.appender.DAY.layout=com.myapp.util.logger.LoggerLayout
      log4j.appender.DAY.layout.ConversionPattern=+{DATE_TIME};{EVENT_ID};{SESSION_ID};{SEVERITY};{MODULE};{THREAD_ID};{EVENT_TYPE};{ERROR_CODE};{DESCRIPTION};{DEBUG_INFO}

      # ===========================================================================

      # SIMPLE FILE OUTPUT DRIVER SETTINGS WITH DEBUG_INFO
      log4j.appender.FIL=org.apache.log4j.FileAppender
      log4j.appender.FIL.File=/var/opt/apps/myapp/var/logs/fil_application.log
      log4j.appender.FIL.Append=false
      log4j.appender.FIL.layout=com.myapp.util.logger.LoggerLayout
      log4j.appender.FIL.layout.ConversionPattern=+{DATE_TIME};{EVENT_ID};{SESSION_ID};{SEVERITY};{MODULE};{THREAD_ID};{EVENT_TYPE};{ERROR_CODE};{DESCRIPTION};{DEBUG_INFO}

      # ===========================================================================

      # DAILY OBSERVATION FILE OUTPUT DRIVER SETTINGS
      log4j.appender.OBS=org.apache.log4j.DailyRollingFileAppender
      log4j.appender.OBS.File=/var/opt/apps/myapp/var/logs/obslog.out
      log4j.appender.OBS.DatePattern=.yyyyMMdd
      log4j.appender.OBS.layout=com.myapp.util.logger.LoggerLayout
      log4j.appender.OBS.layout.ConversionPattern={DESCRIPTION}
      # log4j.appender.OBS.layout.ConversionPattern=+{DATE_TIME};{EVENT_ID};{SESSION_ID};{SEVERITY};{MODULE};{THREAD_ID};{EVENT_TYPE};{ERROR_CODE};{DESCRIPTION};{DEBUG_INFO}




      Regards...

        • 1. Re: log4j file appender
          807597
          Hello Rashshuu.

          I just experienced this exact same scenario today (2004/08/27) and
          I am similarly at a loss to explain it. A quick scan through the Log4j
          bug database did not turn up an exact match (but it could be buried
          somewhere in there).

          If I find anything further I will let you know. Try checking
          http://logging.apache.org/site/bugreport.html yourself and see if
          you can find anything indicating this is an open problem. If not
          one of us should open up a bug report.

          Good luck.
          • 2. Re: log4j file appender
            807597
            Hello,
            i have a problem with DailyRollingFileAppender : it not tiny every wheel as I have indicated. The code is below:
            log4j.logger.it.na.its.csinfo.presentation = DEBUG, A1
            log4j.appender.A1 = org.apache.log4j.DailyRollingFileAppender
            log4j.appender.A1.File = test/it/na/its/csinfo/presentation/CsInfoLog.log
            log4j.appender.A1.DailyRollingFileAppender.DatePattern = '.'yyyy-MM-dd-HH-mm
            log4j.appender.A1.layout = org.apache.log4j.PatternLayout
            log4j.appender.A1.layout.ConversionPattern = %d [%t] %-5p %c %M - %m%n

            May you help me?
            Thanks
            • 3. Re: log4j file appender
              800335
              log4j.appender.A1.DailyRollingFileAppender.DatePattern = '.'yyyy-MM-dd-HH-mm

              should be

              log4j.appender.A1.DatePattern = '.'yyyy-MM-dd-HH-mm
              • 4. Re: log4j file appender
                807597
                Hi guys!

                I just had the exact same probleme with log4j 1.2.9. Somebody got a solution for this? I would be really useful because right now we do have the log for the current day but all the previous day are lost because log4j is rewriting in them.

                Thanks!
                • 5. Re: log4j file appender
                  807597
                  Hi, Onirike ,

                  I met exactly the same problem as yours. How did you solve it?
                  This is my configuration file.

                  log4j.logger.A1=INFO, A1

                  log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
                  log4j.appender.A1.File=/usr/java/jboss-4.0.2/server/default/log/tcmlog/httpproxy_access.log
                  log4j.appender.A1.DatePattern='.'yyyy-MM-dd
                  log4j.appender.A1.Append=false
                  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
                  log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p %m%n

                  Thank you!

                  Message was edited by:
                  coolmobile
                  • 6. Re: log4j file appender
                    807597
                    I found from the log4j 1.3 API javadoc, the DailyRollingFileAppender is deprecated. They use the RollingFileAppender instead and give one sample .

                    Hope it helps!

                    <?xml version="1.0" encoding="UTF-8" ?>
                    <!DOCTYPE log4j:configuration>

                    <log4j:configuration debug="true">

                    <appender name="ROLL" class="org.apache.log4j.rolling.RollingFileAppender">
                    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
                    <param name="FileNamePattern" value="/wombat/foo.%d{yyyy-MM}.gz"/>
                    </rollingPolicy>

                    <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="%c{1} - %m%n"/>
                    </layout>
                    </appender>

                    <root">
                    <appender-ref ref="ROLL"/>
                    </root>

                    </log4j:configuration>
                    • 7. Re: log4j file appender
                      807597
                      did u get solution to this problem