7 Replies Latest reply on Oct 12, 2010 2:04 AM by jaikiran

    Jboss log4j level dynamic switch

    pradeepsreekumar

      Hi All,

      I am having an issue with switching the log level dynamically.I tried using log4j xml and following is the log4j configuration.

      <appender name="FILE" class="org.apache.log4j.RollingFileAppender">

       

            <param name="File" value="${jboss.server.log.dir}/shcapiTest.log"/>
            <param name="Threshold" value="INFO"/>
            <param name="Append" value="false"/>

       

            <layout class="org.apache.log4j.PatternLayout">
               <!-- The default pattern: Date Priority [Category] Message\n -->
               <param name="ConversionPattern" value="%c [%d] %5p %X{token} %C.%M - %m%n"/>
            </layout>
         </appender>

      <category name="com.test.api" additivity="false">
              <appender-ref ref="FILE"/>
             </category>

      <root>
            <appender-ref ref="FILE"/>
         </root>

       

      Also RefreshPeriod is configured in jboss-service.xml.

      But changing the threshold level from INFO to DEBUG is not printing my DEBUG logs

       

      This is how i access the logger

      Logger
                  .getLogger("com.test.api");

      logger.debug("Testing debug");

      Any issue with this configuration.?

        • 1. Re: Jboss log4j level dynamic switch
          jaikiran

          Pradeep Sreekumar wrote:

           


          But changing the threshold level from INFO to DEBUG is not printing my DEBUG logs

          How are you changing that? And where exactly is that log4j.xml located? And which version of JBoss AS?

          • 2. Re: Jboss log4j level dynamic switch
            pradeepsreekumar

            Hi,

            I tried manually editing the log4j.xml in server\default\conf folder.

            Jboss version is 4.2.3

            • 3. Re: Jboss log4j level dynamic switch
              wdfink

              If you change the correct log4j.xml file it should have an effect.

              If you use a EAP (supported version of JBoss) the file is named 'jboss-log4j.xml'.

              Also you must change the log4j configuration within the right folder, in you case the server must be started with '-c default' to be sure.

              • 4. Re: Jboss log4j level dynamic switch
                pradeepsreekumar

                Hi

                I am starting jboss from eclipse ide.

                Also in jboss admin console under log4j section, file name is mentioned as log4j.xml

                while i am changing the file, i can see logs in console that log4j configuration change done.So i think file is getting reloaded.My doubt is regarding the log4j xml configuration.

                • 5. Re: Jboss log4j level dynamic switch
                  wdfink

                  Ok, that looks good.

                  I don't know what the default is for priority, so change as followed:

                  <category name="com.test.api" additivity="false">
                       <priority value="DEBUG"/>

                       <appender-ref ref="FILE"/>
                  </category>

                   

                  You might drop the Threshold element if you want a full logging file (normally I use is for additional appender like CONSOLE/MAIL etc.

                   

                  For more log4j configuration and information see http://logging.apache.org/log4j/1.2/manual.html

                  • 6. Re: Jboss log4j level dynamic switch
                    pradeepsreekumar

                    My requirement is to change the log level dynamically.

                    Currently INFO to DEBUG switch is happening and config file is reloaded.

                    But issue is that other DEBUG logs are coming.

                    But its not coming for com.api.test category  that i defined

                    These are the logger statements used.

                    logger.info("dsfdsfdsjfksdflksdlf;dsfdsf");
                    logger.debug("debuggggggggggggggggggggggggggggg");
                    logger.fatal("fatalllllllllllllllllllllllllll");

                     

                    info and fatal logs are coming. But debug logs are not getting printed

                    • 7. Re: Jboss log4j level dynamic switch
                      jaikiran

                      Is that the exact code and config file you are using? If not, please post real code.