9 Replies Latest reply on Jun 28, 2013 5:13 PM by James Perkins

    How to auto-deploy log4j configuration changes

    Atul Kshirsagar Newbie

      We are migrating from JBoss 5.1 to JBoss 7.2.0. In JBoss 5.1 we use jboss-log4j.xml to control our log4j configuration that is specific to our application. We want to continue to have application specific log4j so I followed the instructions in various posts on this forum and did following:

      1) Added jboss-log4j.xml to META-INF directory in our ear.

      2) Added log4j-extras as a module that is dependent on org.apache.log4j. We need log4j-extras to compress the rolled over log files.

      3) Made log4j-extras as a global module. Adding it as dependency in MANIFEST.MF file did not work (Any idea, why?)

      With these changes I am able to use our existing jboss-log4j.xml and direct the logs to application specific log files.


      However, unlike JBoss 5.1 where the jboss-log4j.xml changes were picked up automatically, in JBoss 7.2 the changes are not picked up and I have to restart JBoss.


      Ours is an exploded deployment and we have auto-deploy-exploded set to false in deployment-scanner subsytem.. By setting it to true the changes get picked up automatically. However, setting it to true results in warning from JBoss that deployment consistency is not guaranteed with auto deployment on for exploded deployments. Also, I noticed that change in log4j configuration file results in deployment of whole application all over again, which results in reinitializing the states of all the Singleton EJBs that we have. This is not desired behavior and we want to achieve auto deployment of just jboss-log4j.xml. Is there any way to achieve it?




        • 1. Re: How to auto-deploy log4j configuration changes
          Stephen Coy Master

          Hi there,


          You can control AS7.x+ logging at runtime using the CLI, as described in https://docs.jboss.org/author/display/AS71/CLI+Recipes#CLIRecipes-Addalogcategory.

          1 of 1 people found this helpful
          • 2. Re: How to auto-deploy log4j configuration changes
            Atul Kshirsagar Newbie

            I tried changing the logging configuration using CLI as you indicated but looks like it works only for the loggers configured through logging subsystem in standalone-full.xml. However, this approach doesn't seem to work for the categories configured by jboss-log4j.xml in META-INF of application ear. I used jconsole CLI plugin to check if I can build CLI for jboss-log4j.xml under application deployment but couldn't find any way to do it.

            • 3. Re: How to auto-deploy log4j configuration changes
              Stephen Coy Master

              I was not actually aware that there was any support for jboss-log4j.xml in the way that you describe in earlier versions of JBossAS.


              In any event, I don't believe that that capability exists anymore.


              You can include application specific logging configuration in the logging subsystem. I think this is actually preferable because the server configuration gets propogated to the various nodes in a cluster.


              It looks like you're deploying an exploded ear just so that you can get at the logging configuration. This is no longer necessary if you push the config into the server itself.


              In fact, you write a CLI script that configures logging, etc and deploys your application as well.

              • 4. Re: How to auto-deploy log4j configuration changes
                Wolf-Dieter Fink Master

                As far as I know if you add such logging configuration to the application you need to re-deploy the application, this is possible with the CLI if you use exploded deployment.

                I not recommend to use autodeploy (disabled by default) for exploded deployments as each filechange will force a redeploy.

                • 5. Re: How to auto-deploy log4j configuration changes
                  Stephen Coy Master

                  Does this mean that AS7.x supports the use of jboss-log4j.xml?


                  With or without application provided jars?


                  In AS7.x (and presumably other JEE6+ compliant containers) the content of an app.ear/META-INF directory is inaccessible from the application classloader.

                  • 6. Re: How to auto-deploy log4j configuration changes
                    James Perkins Master

                    Yes you can use a jboss-log4j.xml within a deployment to configure log4j. This works in EAP 6.1, WildFly and the AS 7.2.0.Final tag if you build off it. I'm not sure the differences in log4j.xml and jboss-log4j.xml if there are any. Essentially what it does is just configure it as if it was a log4j.xml file.



                    James R. Perkins

                    • 7. Re: How to auto-deploy log4j configuration changes
                      James Perkins Master

                      There is no built-in support for runtime changes to log4j configuration files. You either have to use something like the org.apache.log4j.xml.DOMConfigurator.configureAndWatch() in internal code or use the logging subsystem. While a bit on the buggy side you can use log4j appenders as custom-handlers in the logging subsystem which would allow for runtime changes and you could leave the jboss-log4j.xml file out of your deployment.



                      James R. Perkins

                      1 of 1 people found this helpful
                      • 8. Re: How to auto-deploy log4j configuration changes
                        Atul Kshirsagar Newbie

                        Thanks everyone for your comments. Since changing logging level at runtime without having to redeploy application is one of very important requirements from development team I will have to switch to using jboss logging subsystem. We used org.apache.log4j.rolling.RollingFileAppender to compress the rolled over files. Is there any way we can achieve compression of the rolled over log files using perdiocFileHandler?


                        I tried configuring org.apache.log4j.rolling.RollingFileAppender as custom-handler in jboss logging subsystem as follows:


                        <custom-handler name="TEST" class="org.apache.log4j.rolling.RollingFileAppender" module="org.apache.log4j-extras">


                                        <property name="rollingPolicy" value="org.apache.log4j.rolling.TimeBasedRollingPolicy"/>       

                                        <property name="File" value="${dcm.home.dir}/logs/server/test.log"/>




                        But jboss fails to start complaining that parameter type is not correct. Looks like I will have to write a wrapper Handler class and deploy it as a module and use it in logging subystem as custom handler to achieve the desired behavior. If there is any other easier way to do it then please let me know.



                        • 9. Re: How to auto-deploy log4j configuration changes
                          James Perkins Master

                          Ah, it probably can't set the rollingPolicy since it requires an unknown type. The periodic-rotating-file-handler will not compress files. Really though you could just us a cron job to do that if needed. The other option would be, as you suggest, just writing a custom handler.



                          James R. Perkins