2 Replies Latest reply on Mar 22, 2013 8:08 AM by suikast42

    Extends from PeriodicRotatingFileHandler

    suikast42

      Hi guys,

       

      I want to extend the behaviour of PeriodicRotatingFileHandler. For that I create a jboss module and extends from PeriodicRotatingFileHandler and override only

       

        @Override

        protected void preWrite(ExtLogRecord record){

          super.preWrite(record);

          deleteOldFiles();

        }

       

       

      <custom-handler name="MyAppender" class="myg.handler.PeriodicRotatingFileHandlerExtended" module="my.libs">
                     
                      <formatter>
                          <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                      </formatter>
                      <properties>
                           <property name="relativeTo" value="${jboss.server.log.dir}/app"/>
                          <property name="file" value="Application.log"/>
                          <property name="suffix" value=".yyyy-MM-dd"/>
                          <property name="maxBackupDays" value="2" /> <!-- This is my needed feature -->
                          <property name="append" value="true"/>
                      </properties>
                  </custom-handler>
      

       

      I can debug this handler. It semms so thats works fine but my logfile is everytime empty.  Did I miss something ??

        • 1. Re: Extends from PeriodicRotatingFileHandler
          suikast42

          Its strange very strange.  I don't understand the the lifecycle of the handlers.

           

          If I do this :

           

            @Override

            protected void doPublish(ExtLogRecord record){

                try {

                  fileOutputStream = new FileOutputStream(getFile(), true);

                  setOutputStream(fileOutputStream);

                } catch (FileNotFoundException e) {

                  e.printStackTrace();

                }

            

              super.doPublish(record);

            }

           

          then the handler writes the entries in the file otherwise its empty .

          • 2. Re: Extends from PeriodicRotatingFileHandler
            suikast42

            After I switch to 7.2.0.Final I can use log4j appenders as custom-logger. So my problem is solved.