1 2 Previous Next 19 Replies Latest reply on Apr 14, 2012 2:38 PM by jamezp

    Log4j configuration in JBoss AS7

    haroonfoad

      Dear All,

      I was using log4j in JBoss 4.2.2.GA without any hardships or obstacles,

      but now with JBoss AS7 I dont know how to configure it.

       

      In JBoss AS4 , I did like this:

      1. in jboss-log4j.xml I added:

       

      <category name="com.lit.wessal">
              <priority value="INFO"/>
              <appender-ref ref="WESSAL_WEB_APP_LOG"/>
      </category>
      
      <appender name="WESSAL_WEB_APP_LOG" class="org.jboss.logging.appender.DailyRollingFileAppender">
              <param name="Append" value="true"/>
              <param name="File" value="${jboss.server.home.dir}/log/wessal-web.log"/>
              <!-- Rollover at midnight each day -->
              <param name="DatePattern" value="'.'yyyy-MM-dd"/>
              <layout class="org.apache.log4j.PatternLayout">
                      <param name="ConversionPattern" value="%d %-5p [%c{1}] %l - %m%n"/>
              </layout>
      </appender>
      
      

       

       

      2. in Log.java

       

      package com.lit.wessald.mavenproject6.hibernateutil;
      
      
      import org.apache.log4j.Logger;
      
      
      /**
       * Defines the logger for Log4J logging.
       * 
       * 
       */
      public class Log {
                private static String LIS_LOGS = "com.lit.wessal";
        
                private static Logger _logger = Logger.getLogger(LIS_LOGS);
        
                /**
                 * DOCUMENT ME!
                 * 
                 * @return DOCUMENT ME!
                 */
                public static Logger getLogger() {
                          return _logger;
                }
        
                /**
                 * DOCUMENT ME!
                 * 
                 * @param classObject
                 *            DOCUMENT ME!
                 * 
                 * @return DOCUMENT ME!
                 */
                public static Logger getLogger(Class<?> classObject) {
                          return _logger = Logger.getLogger(classObject);
                }
      
      
                /**
                 * DOCUMENT ME!
                 * 
                 * @param className
                 *            DOCUMENT ME!
                 * 
                 * @return DOCUMENT ME!
                 */
                public static Logger getLogger(String logTitle) {
                          return _logger = Logger.getLogger(logTitle);
                }
      
      
      }
      
      

       

       

      How can I do the same thing in JBoss AS7.

      Please help.

        • 1. Re: Log4j configuration in JBoss AS7
          haroonfoad

          Any idea dears

          • 2. Re: Log4j configuration in JBoss AS7
            haroonfoad

            Help

            • 3. Re: Log4j configuration in JBoss AS7
              wdfink

              The class can be used in AS7 as well.

              The configuration will be located in

              standalone/configuration/standalone.xml  (standalone mode)

              domain/configuration/domain.xml (domain mode)

               

              See the logging subsystem.

              • 4. Re: Log4j configuration in JBoss AS7
                haroonfoad

                Thanks Mr. Wolf-Dieter:

                You cheered me up.

                But what should I do.

                Copy the content of the jboss-log4j.xml to the inside of standalone.xml file or what and delete the jboss-log4j.xml file?

                Along, I'll try to search for the logging subsystem.

                • 5. Re: Log4j configuration in JBoss AS7
                  wdfink

                  No, the syntax will be different.

                   

                  See the <logger> instead of <category>

                  and use the <periodic-rotating-file-handler> as template.

                   

                  See the admin guide here for more informations.

                  • 6. Re: Log4j configuration in JBoss AS7
                    haroonfoad

                    Thanks dear,

                    I will have look at it and inform you with the results.

                    • 7. Re: Log4j configuration in JBoss AS7
                      haroonfoad

                      Dear Mr Wolf-Dieter,

                      Using the admin cosole on jboss as7 , I added a handler and register a log category.

                      This is what has been added to the standalone.xml file:

                       

                      <periodic-rotating-file-handler name="wessal-file" autoflush="true">

                           <level name="INFO"/>

                           <encoding value="UTF-8"/>

                           <formatter>

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

                           </formatter>

                           <file relative-to="jboss.server.log.dir" path="wessal-web.log"/>

                           <suffix value=".yyyy-MM-dd"/>

                           <append value="true"/>

                      </periodic-rotating-file-handler>

                       

                      <logger category="com.lit.wessal">

                           <level name="INFO"/>

                           <handlers>

                                <handler name="wessal-file"/>

                           </handlers>

                      </logger>

                       

                      But I don't see any thing in wessal-web.log file.

                      Is there any problem in Log.java file?


                      • 8. Re: Log4j configuration in JBoss AS7
                        thinksteep

                        Hi Haroon,

                         

                        Could you check server.log and see any WARN/ERROR related to log4j?

                         

                        Post server.log entries if possible.

                         

                        Here are couple of things to make sure:

                         

                        1) Are you copying log4j with your application?

                        2) If so, did you exclude log4j in jboss-deployment-strucutre file or not?

                         

                        Thank you.,

                        • 9. Re: Log4j configuration in JBoss AS7
                          jamezp

                          That looks like it should be working. Have you tried restarting or reloading to server?

                          • 10. Re: Log4j configuration in JBoss AS7
                            haroonfoad

                            Dear Mr.Thinksteep,

                            Yes as you said there are errors related to log as I think.

                            Here they are:

                             

                            10:50:00,095 ERROR [stderr] (LisDisplayerScheduler_Worker-0) SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

                            10:50:00,095 ERROR [stderr] (LisDisplayerScheduler_Worker-0) SLF4J: Defaulting to no-operation (NOP) logger implementation

                            10:50:00,095 ERROR [stderr] (LisDisplayerScheduler_Worker-0) SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

                             

                             

                             

                            1) Are you copying log4j with your application?

                            No. As I migrated from JBoss AS4. I don't have any log4j file in my application.

                            As you know in JBoss AS4, I only made changes in the jboss-log4j.xml which comes with AS4 itself.

                             

                            2) If so, did you exclude log4j in jboss-deployment-strucutre file or not?

                            I dont have any file named jboss-deployment-structure.xml in my application.

                            Should I use it, and how?

                            • 11. Re: Log4j configuration in JBoss AS7
                              haroonfoad

                              Dear Mr.James Perkins:

                              Yes. I tried to restart it more than one time.

                              • 12. Re: Log4j configuration in JBoss AS7
                                haroonfoad

                                I don't see the previous errors after adding these two dependencies:

                                 

                                <dependency>

                                            <groupId>org.slf4j</groupId>

                                            <artifactId>slf4j-log4j12</artifactId>

                                            <version>1.6.4</version>

                                        </dependency>

                                 

                                 

                                        <dependency>

                                            <groupId>org.slf4j</groupId>

                                            <artifactId>slf4j-api</artifactId>

                                            <version>1.6.4</version>

                                        </dependency>

                                 

                                But I still have this error:

                                11:47:13,962 ERROR [stderr] (MSC service thread 1-2) log4j:WARN No appenders could be found for logger (org.ajax4jsf.renderkit.ChameleonRenderKitFactory).

                                11:47:13,962 ERROR [stderr] (MSC service thread 1-2) log4j:WARN Please initialize the log4j system properly.

                                 

                                And my wessal-web.log file is still empty.

                                • 13. Re: Log4j configuration in JBoss AS7
                                  gramark

                                  Perhaps my instructions in https://community.jboss.org/thread/198196 can be of any help?

                                  • 14. Re: Log4j configuration in JBoss AS7
                                    jamezp

                                    I'm a bit confused here. It looks like you're using log4j, but you're importing slf4j as well. Which logging facade is your application using?

                                    1 2 Previous Next