6 Replies Latest reply on Apr 10, 2007 6:12 PM by Brandon Barlow

    How do I change the log4j levels dynamically?

    Niraj Patel Newbie

      I was wondering if it is possible to change the default log4j level (currently set to INFO in log4j.xml config file) while the server is still running and it won't interrupt the running services.

      I can't change the config file as this is a live environment. Was hoping the jmx-console might allow me to do it but couldnt spot anything!

      Also does anyone of any resources which might help me understand a framework or the principles behind dynamic logging through Jboss?

      Any help would be appreciated.

        • 1. Re: How do I change the log4j levels dynamically?
          Niraj Patel Newbie

          Sorry forgot to mention that I am using JBoss 3.2.3 and am looking to upgrade in the future, so if there is a way it can work with both versions even better :)

          • 2. Re: How do I change the log4j levels dynamically?
            jaikiran pai Master

            Just change the log4j.xml and save it. There's a Log4jServiceTimerTask which executes every 60 seconds and picks up the changes to the log4j.xml. You DONT have to restart the appserver.

            • 3. Re: How do I change the log4j levels dynamically?
              Niraj Patel Newbie

               

              "jaikiran" wrote:
              Just change the log4j.xml and save it. There's a Log4jServiceTimerTask which executes every 60 seconds and picks up the changes to the log4j.xml. You DONT have to restart the appserver.



              I cant change the log4j.xml file as its on a live server which developers don't have write access to, only our sys admins do and they are never here :)

              • 4. Re: How do I change the log4j levels dynamically?
                jaikiran pai Master

                Yes, you can do it through jmx-console. Through the jmx-console (http://server:port/jmx-console), look for the following service:

                service=Logging,type=Log4jService


                Use the setLoggerLevel method of this service to set the level of a logger. Here's the javadoc of this API:

                /**
                * Sets the level for a logger of the give name.
                *
                * <p>Values are trimmed before used.
                *
                * @jmx:managed-operation
                *
                * @param name The name of the logger to change level
                * @param levelName The name of the level to change the logger to.
                */
                public void setLoggerLevel(final String name, final String levelName)



                • 6. Re: How do I change the log4j levels dynamically?
                  Brandon Barlow Newbie

                  I have slightly more strict requirements, and was hoping for some help.

                  In our legacy J2SE environment, our application's JVM served up a very basic webpage that allowed us to dynamically alter the log4j Logger levels at runtime, without editing any log4j configuration files. The webpage was simply a form that listed all of the Loggers in the JVM in a hierarchical tree view (very much like how Chainsaw displays them), with comboboxes containing the available Levels for each Logger. The user could then choose new Levels for any or all loggers and submit the form. The server parsed the form arguments and made Logger.setLoggerLevel() calls appropriately.

                  This type functionality is extremely useful to my team, as we often have less technically skilled team members sitting at the system, trying to debug problems while consulting with the engineering team over the phone. It's much easier to ask someone to work with the tree view than to work with either the JBoss web console, the Sun JConsole, or via editing the log4j.xml file.

                  Is there some industry standard or open source tool that does what we're looking for, or is editing the log4j.xml file (or using the web console) really the standard, preferred approach to dynamically altering Logger levels? If not, what do you think the best approach for adding this functionality to the JBoss environment would be?

                  Thanks