5 Replies Latest reply on Nov 20, 2012 8:21 AM by sfcoy

    Logging

    akash_bansal

      Pls. help me...

       

      Is there any substitute of NonCatalogLogger of Weblogic in JBoss 7.1. I have an application which has several classes in which Log Messages has to be sent in (1) application Log File and (2) server.log file of JBoss 7.1. I know one way is to create two separate appenders to divert log messages to specifc log file. But I want to know the way which is similar to NonCatalogLogger provided by Weblogic.

        • 1. Re: Logging
          nickarls

          I doubt that that many over here are familiar with WL loggers so perhaps it's best to sticking to what you are trying to acheive.

          So you want logging to go into two files but you don't want to have separate appenders? (and a side-question, if so, why?)

          • 2. Re: Logging
            akash_bansal

            I mean just want to send log messages to server log file without doing any change in log4j.config file.

            • 3. Re: Logging
              nickarls

              Well the default ROOT logger points to CONSOLE and FILE, and FILE is the server.log so I don't see why it shouldn't work OOTB.

              • 4. Re: Logging
                akash_bansal

                In one of the java file, I have two loggers, one of Log4j and other is of org.jboss.logging.Logger.   Log4j logger is configured to send log to a differnet file. While I want JBoss specific logger to send log to server.log file inside JBoss Server Log folder. What is happeing is JBoss logger and log4j logger are logging message in both location that is server.log of jboss and other file. Below is my log4j configuration :

                 

                <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"

                    debug="true">

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

                        <param name="file" value="c:/logs/log4j-war-.log" />

                        <param name="append" value="true" />

                        <param name="maxFileSize" value="20000000" />

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

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

                            <param name="ConversionPattern" value="%d [%x] %c{5}- %m%n" />

                        </layout>

                    </appender>

                    <root>

                        <level value="debug" />

                        <appender-ref ref="ROLLING_FILE" />

                    </root>

                </log4j:configuration>

                 

                code of class file where I want to user both Logger is :

                 

                import org.apache.log4j.Logger;

                public class LogTester {

                    Logger logger = Logger.getLogger(getClass().getName());

                    org.jboss.logging.Logger jbossLogger = org.jboss.logging.Logger.getLogger(getClass().getName());

                    public void log(){

                        logger.info("Logging INFO message");

                        logger.debug("Logging DEBUG message");

                        jbossLogger.info("Logging INFO message using JBOSS LOGGER");

                        jbossLogger.debug("Logging DEBUG message using JBOSS LOGGER");

                    }

                }

                 

                Please advise where is configuration going wrong.

                • 5. Re: Logging
                  sfcoy

                  The WebLogic NonCatalogLogger is specifically for writing log messages to the server log.

                   

                  This is the default behaviour in JBoss AS7.x. In fact, it does not matter what logging API you use, JBoss will spit out your log messages in the server log.

                   

                  If you want to write specific log messages to a separate file you need to do a few things:

                   

                  • Create one logger as usual with Logger.getLogger(getClass().getName())
                  • Create a second logger (with the same API) with a different category name: Logger.getLogger("APP." + getClass().getName())
                  • Create a second file appender in the JBoss logging configuration for your special log file
                  • Create a logger in the JBoss logging configuration that is associated with the second file appender, specifying it's category as "APP.your.package.name"

                   

                  I've just used APP as an example. It can be any string you like. Just be aware that it should have a Java package name like structure.

                   

                   

                  {code:xml}

                               ...

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

                                  <formatter>

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

                                  </formatter>

                                  <file path="c:/logs/myapp.log"/>

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

                                  <append value="true"/>

                              </periodic-rotating-file-handler>

                              ...

                              <logger category="APP.your.package.name">

                                  <level name="INFO"/>

                                  <handlers>

                                      <handler name="MyAppLogHandler"/>

                                  </handlers>

                              </logger>

                              ...

                  {code}

                   

                  You can find more information at AS71 Logging Configuration.