5 Replies Latest reply on Sep 3, 2010 2:32 AM by isabelc

    Rotate run.log

    isabelc

      We are running JBoss 4.2.3 GA as Windows Service. The console log is written into the run.log. As the run.log constantly grows larger we would like to rotate the log on a daily basis.

       

      Therefor I added another appender to the jboss-log4j.xml:

       

      <appender name="RUNLOG">
            <errorHandler/>
            <param name="File" value="${jboss.server.log.dir}/run.log"/>
            <param name="Append" value="false"/>
            <!-- Rollover at midnight each day -->
            <param name="DatePattern" value="'.'yyyy-MM-dd"/>
            <layout>
               <!-- The default pattern: Date Priority [Category] Message\n -->
               <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
            </layout>
      </appender>

       

      Unfortunately this led to the following error message on startup in the run.log:

       

      00:07:20,307 INFO  [Log4jService$URLWatchTimerTask] Configuring from URL: resource:jboss-log4j.xml
      log4j error: setFile(null,false) call failed.
      java.io.FileNotFoundException: C:\opt\JBoss\jboss-4.2.3.GA\server\default\log\run.log (Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird)
          at java.io.FileOutputStream.open(Native Method)
          at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
          at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
          at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)
          at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)
          at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:215)
          at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)
          at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:220)
          at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:150)
          at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)
          at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)
          at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)
          at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)
          at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)
          at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
          at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:743)
          at org.jboss.logging.Log4jService$URLWatchTimerTask.reconfigure(Log4jService.java:643)
          at org.jboss.logging.Log4jService$URLWatchTimerTask.run(Log4jService.java:582)
          at org.jboss.logging.Log4jService.setup(Log4jService.java:460)
          at org.jboss.logging.Log4jService.createService(Log4jService.java:476)
          at org.jboss.system.ServiceMBeanSupport.jbossInternalCreate(ServiceMBeanSupport.java:260)
          at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:243)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
          at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
          at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
          at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
          at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
          at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
          at $Proxy0.create(Unknown Source)
          at org.jboss.system.ServiceController.create(ServiceController.java:330)
          at org.jboss.system.ServiceController.create(ServiceController.java:273)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
          at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
          at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
          at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
          at $Proxy4.create(Unknown Source)
          at org.jboss.deployment.SARDeployer.create(SARDeployer.java:260)
          at org.jboss.deployment.MainDeployer.create(MainDeployer.java:969)
          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:818)
          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
          at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
          at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
          at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
          at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
          at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
          at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
          at $Proxy5.deploy(Unknown Source)
          at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
          at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
          at org.jboss.Main.boot(Main.java:200)
          at org.jboss.Main$1.run(Main.java:508)
          at java.lang.Thread.run(Thread.java:619)
      log4j:ERROR Either File or DatePattern options are not set for appender [RUNLOG].

       

      The sentence in brackets "(Der Prozess kann nicht auf die Datei zugreifen, da sie von einem  anderen Prozess verwendet wird)" means something like: The process can't access the file, as the it is used by another process.

       

      What is the issue here? My idea is that the Jboss is already accessing the file as it writes the console output into the run.log. If so, is there any other way to rotate it anyways?

        • 1. Re: Rotate run.log
          isabelc

          It seems no one has an idea yet, what I could try. Is there anyone who successfully rotates the run.log?

          • 2. Re: Rotate run.log
            peterj

            Go into the jboss0log4j.xml file and change the CONSOLE appender to use the RollingFileAppender class instead of the ConsoleAppender class.

             

            You will still end up with run.log, and it will not be rotatable, but at least it will stay very small.

            • 3. Re: Rotate run.log
              isabelc

              Would you have a working example for me?

               

              At the moment my CONSOLE appender looks like this:

               

              <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
              <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                    <param name="Target" value="System.out"/>
                    <param name="Threshold" value="INFO"/>

                    <layout>
                       <param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{1}] %m%n"/>
                    </layout>

              </appender>

               

              With this ConsoleAppender I can't simply exchange it with the RollingFileAppender as their parameter requirements differ a lot.

              As I wrote in my first post I tried to add a DailyRollingFileAppender additionally to this ConsoleAppender. But on startup Jboss encounters the exception which I posted earlier.

              • 4. Re: Rotate run.log
                peterj

                Use the FILE appender as an example of how to change the CONSOLE appender. Actually, the RUNLOG appender is also a good example.

                 

                >>My idea is that the Jboss is already accessing the file as it writes the  console output into the run.log.

                No, it does not work that way. When you redirect stdout to a file (run.log) that counts as one file handle within the JVM. Then when log4j attempts to open the same file, that is as a separate file handle, and that causes the problem you saw.

                 

                Here are a few choices to fix this:

                 

                option a) Remove RUNLOG, change CONSOLE to look like FILE or RUNLOG, use a name othert than run.log for the log file.

                 

                option b) Change RUNLOG to use a different file. Remove CONSOLE.

                 

                In general, make sure that the file used to redirect stdout and the file used to log are not the same file!

                • 5. Re: Rotate run.log
                  isabelc

                  I never gave you any feedback to your suggestions Peter. I realized option a) which works very well.

                   

                  The following is my configuration for log4j which rotates a new logfile called console.log.

                   

                  <appender name="CONSOLE" class="org.jboss.logging.appender.DailyRollingFileAppender">
                        <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
                        <param name="File" value="${jboss.server.log.dir}/console.log"/>
                        <param name="Threshold" value="INFO"/>
                        <param name="Append" value="true"/>
                        <param name="DatePattern" value="'.'yyyy-MM-dd"/>
                        <layout class="org.apache.log4j.PatternLayout">
                           <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
                        </layout>
                     </appender>

                   

                  What happens is this:

                   

                  On startup the JBoss still logs its console output into run.log, but only until it activated the log4j configuration. Afterwards all the output goes into the console.log which can be rotated. I still have a run.log that won't be rotated, but that doesn't matter as it is really small and doesn't grow.

                   

                  Many thanks to Peter again!