3 Replies Latest reply on Dec 11, 2013 12:59 PM by Indranil Majumder

    JBOSS - log rotate and zip

    Ricardo Esteves Newbie

      Hi,

       

      I've got this configuration:

       

      <appender name="smint-tmn-sat1.async" class="org.apache.log4j.AsyncAppender">
           <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
           <appender-ref ref="smint-tmn-sat1.file"/>
           <param name="BufferSize" value="8192"/>
         </appender>


         <appender name="smint-tmn-sat1.file" class="org.jboss.logging.appender.RollingFileAppender">
           <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
           <param name="File" value="${jboss.server.log.dir}/smint-sat1_smint_unip.log"/>
           <param name="Append" value="true"/>
           <param name="MaxFileSize" value="300MB"/>
           <param name="MaxBackupIndex" value="20"/>
           <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern" value="%d %-5p [%c:%t] %m %n"/>
           </layout>
         </appender>


         <category name="smint-tmn-sat1" additivity="false">
            <priority value="INFO"/>
            <appender-ref ref="smint-tmn-sat1.async"/>
         </category>

       

      How can i make jboss compress the log after it rotates it?

        • 1. Re: JBOSS - log rotate and zip
          Wolf-Dieter Fink Master

          I've done this via cron job for all log files older than ..., also the files are moved to a slower storage.

          I don't think that there is a appender for that, also you should notice that the appender might block the logging during the rotate. You might run into issues in this case.

          • 2. Re: JBOSS - log rotate and zip
            Ricardo Esteves Newbie

            But isn't there a way to make jboss do it instead of using an external script?

            • 3. Re: JBOSS - log rotate and zip
              Indranil Majumder Newbie

              yes there is run :: your own appender:

              Step 1: Create a custom appender module(module.xml)

              <?xml version="1.0" encoding="UTF-8"?>

              <module xmlns="urn:jboss:module:1.0" name="loggers">

                   <resources>  

                         <resource-root path="MyLogger.jar"/>

                   </resources>

                   <dependencies>

                        <module name="org.jboss.logging"/>

                   </dependencies>

              </module>

               

               

              Step 2: Use a java code to do whatever you want:

              Something like:

              public class MyLogger extends Handler{

                @Override

                public void publish(LogRecord record) {

                String levelName = record.getLevel().getName();

                String className = record.getSourceClassName();

                String methodName = record.getSourceMethodName();

                String logMsg = getFormatter().format(record);

                System.out.println("Custom Logger : ["+levelName+"]["+className+"]["+methodName+"]["+logMsg+"]");

                    // DO WHATEVER YOU WANT e.g zipping , mailing , deleting etc.

                }

                @Override

                public void flush() {  // TODO Auto-generated method stub  }

                @Override

                public void close() throws SecurityException {  // TODO Auto-generated method stub  }

              }

               

               

              Step 3: Create a jar of your custom logger and put the module.xml along with the jar under the modules folder of your jboss installation directory.

              Step 4: Load the module from your standalone or domain xml in the <subsystem xmlns="urn:jboss:domain:logging:1.1">

                <subsystem xmlns="urn:jboss:domain:logging:1.1">

                          <console-handler name="CONSOLE">

                              <level name="INFO"/>

                              <formatter>

                                  <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                              </formatter>

                          </console-handler>

                          <periodic-rotating-file-handler name="FILE">

                              <formatter>

                                  <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                              </formatter>

                              <file relative-to="jboss.server.log.dir" path="server.log"/>

                              <suffix value=".yyyy-MM-dd"/>

                              <append value="true"/>

                          </periodic-rotating-file-handler>

                         <custom-handler name="MyCustomHandler" class="loggers.custom.MyLogger" module="loggers.custom">

                               <level name="INFO" />

                               <formatter>

                                    <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n" />

                               </formatter>

                               <properties>

                               </properties>

                          </custom-handler>

                          <logger category="com.arjuna">

                              <level name="WARN"/>

                          </logger>

                          <logger category="org.apache.tomcat.util.modeler">

                              <level name="WARN"/>

                          </logger>

                          <logger category="sun.rmi">

                              <level name="WARN"/>

                          </logger>

                          <logger category="jacorb">

                              <level name="WARN"/>

                          </logger>

                          <logger category="jacorb.config">

                              <level name="ERROR"/>

                          </logger>

                          <root-logger>

                              <level name="INFO"/>

                              <handlers>

                                  <handler name="CONSOLE"/>

                                  <handler name="FILE"/>

                                  <handler name="MyLogger"/>

                              </handlers>

                          </root-logger>

                      </subsystem>