3 Replies Latest reply on Aug 3, 2012 12:30 PM by wdfink

    How to set my app level log4j to use JBoss Log levels

    elangovans

      Hi, Might be a simple question. But I could not find the answer. I am using JBoss AS 7.1. Slf4j with Log4j as provider.

       

      I have a log4j.xml in my war, as simple as,

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

              <param name="file" value="${jboss.server.log.dir}/loghubtest.log"/>

              <param name="MaxFileSize" value="100KB"/>

              <param name="MaxBackupIndex" value="10"/>

              <layout class="org.apache.log4j.PatternLayout">

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

              </layout>

          </appender>

       

       

          <category name="com.intuit.loghub">

              <priority value="${jboss.server.log.threshold:INFO}"/>

              <appender-ref ref="R"/>

          </category>

       

       

          <!-- ======================= -->

          <!-- Setup the Root category -->

          <!-- ======================= -->

       

       

          <root>

              <!--

                Set the root logger priority via a system property. Note this is parsed by log4j,

                so the full JBoss system property format is not supported; e.g.

                setting a default via ${jboss.server.log.threshold:WARN} will not work.

              -->

              <priority value="${jboss.server.log.threshold:INFO}"/>  <!---- this is not working as mentioned in the above comment. This used to work in the previous version JBoss.  -->

              <appender-ref ref="R"/>

          </root>

       

      Obviously, If I hardcode my log level (INFO, DEBUG, etc.) it logs per the level hardcoded. If I want to use control using JBoss log level or JBoss admin console, how do I set. Please help.

       

      Thanks in advance.

        • 1. Re: How to set my app level log4j to use JBoss Log levels
          wdfink

          I prefere the configuration in JBoss and not provide a app specific log4j.xml.

           

          In that case you can control the levels by using CLI (i.e. standalone server)

          /subsystem=logging/logger=com.intuit.loghub:add(level="ERROR")

          /subsystem=logging/logger=com.intuit.loghub:write-attribute(name=level, value=TRACE)

           

          It is also possible to add a file appender to use your app logfile.

          • 2. Re: How to set my app level log4j to use JBoss Log levels
            elangovans

            Thanks for the quick response, Wolf! Thats a good idea. I will bounce that with my Operations team.

             

            However, there is a little bit more to the puzzle.

             

            I have a JSONPattenLayout class that we develoed internally and structure the log output in JSON format. If I put in the logger configuration in standalone.xml, is it possible to ue my own layout class? I beleive, if this class is not available during server startup the deployment will fail, right? How do I add any custom config like JSONPatternLayout?

            • 3. Re: How to set my app level log4j to use JBoss Log levels
              wdfink

              I never try that.

              You might have a look into the doc here