3 Replies Latest reply on Apr 10, 2013 5:08 PM by jamezp

    Jboss AS7.1 Async Handlers over Custom Handlers

    mantonec

      Hello,

       

      I've created a Custom Handler that extends PeriodicRotatingFileHandler and defined a category for it.

       

       

                  <custom-handler name="ACTIVATION" class="com.mycompany.CustomPeriodicFileHandler" module="com.mycompany.dffp.common">
                      <level name="DEBUG"/>
                      <formatter>
                          <pattern-formatter pattern="%d{HH:mm:ss,SSS} | %X{logts} | %X{clientId} | %-5p | %X{tsoId} | %X{activityName} | %X{taskName} | %X{engineName} | %m%n"/>
                      </formatter>
                      <properties>
                          <property name="fieldKey" value="activityName"/>
                          <property name="fieldValue" value="ACTIVATION"/>
                          <property name="filePath" value="/home/michele/tmp"/>
                          <property name="outFile" value="ACTIVATION"/>
                          <property name="suffixOutFile" value=".log"/>
                          <property name="autoFlushValue" value="true"/>
                          <property name="appendValue" value="true"/>
                          <property name="logSuffix" value=".yyyy-MM-dd"/>
                      </properties>
                  </custom-handler>
      ...
                <logger category="com.mycompany.logger" use-parent-handlers="false">
                      <level name="DEBUG"/>
                      <handlers>
                          <handler name="ACTIVATION"/>
                      </handlers>
                  </logger>
      
      

       

       

      All works fine but i want to take advantages of Async Handler in order to avoid business logic be affected by log's lags.

      So i've changed the configuratios as follows

       

       

                  <async-handler name="DffpAsyncLogger">
                      <level name="ALL"/>
                      <queue-length value="1024"/>
                      <overflow-action value="block"/>
                      <subhandlers>
                          <handler name="ACTIVATION"/>
                      </subhandlers>
                  </async-handler>
      
                  <custom-handler name="ACTIVATION" class="com.mycompany.CustomPeriodicFileHandler" module="com.mycompany.dffp.common">
                     ...
                     no changes 
                     ...
                  </custom-handler>
      
                  <logger category="com.mycompany.logger" use-parent-handlers="false">
                      <level name="DEBUG"/>
                      <handlers>
                          <handler name="DffpAsyncLogger"/>
                      </handlers>
                  </logger>
      
      
                
      
      

       

      Now i can't see my log neither in server logs neither in applicative logs.

       

      Please, could someone give me a suggestion ?

       

      Thanks a lot,

      Michele

        • 1. Re: Jboss AS7.1 Async Handlers over Custom Handlers
          jamezp

          I see you're using a property called autoFlushValue, does this delegate to the PeriodicRotatingFileHandler's setAutoFlush()? If not you might want to set autoFlush to be true. It's the default in newer versions and there was a bug with autoFlush being false with subhandlers of the async handler.

           

          --

          James R. Perkins

          • 2. Re: Jboss AS7.1 Async Handlers over Custom Handlers
            mantonec

            James, thanks for your response.

             

            Yes, autoFlushValue is the attribute used to set the value of autoFlush. Follows the body of my customHandler.

             

             

            private String fieldKey;
            private String fieldValue;
            
            
            private String filePath;
            private String outFile;
            private String suffixOutFile;
            private boolean autoFlushValue;
            private boolean appendValue;
            private String logSuffix;
            
            
            @Override
            public boolean isLoggable( LogRecord arg0 ) {
              if( fieldValue.equals( MDC.get( fieldKey ) )) {
                try {
                  String logFile = filePath + File.separator + outFile + "_" + MDC.get( Constants.CLIENT_ID ) + suffixOutFile;
            
            
                  super.setFileName( logFile );
                  super.setFile( new File( logFile ) );
                  super.setAutoFlush( autoFlushValue );
                  super.setAppend( appendValue );
                  super.setSuffix(logSuffix);
                } catch (FileNotFoundException e) {
                  e.printStackTrace();
                }
                return true;
              }
              else {
                return false;
              }
            }
            
            
            • 3. Re: Jboss AS7.1 Async Handlers over Custom Handlers
              jamezp

              You could try replacing the jboss-logmanager jar with the 1.4.1.Final version. Handlers by default auto-flush is set to true and there were some improvements to how the async handler handled the auto-flush.

               

              Short of that I'm not too sure what it could be. I've only used the async handler for test and in my tests it has worked okay.

               

              --

              James R. Perkins