-
1. Re: Logging
nickarls Nov 20, 2012 2:41 AM (in response to akash_bansal)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 Nov 20, 2012 4:38 AM (in response to nickarls)I mean just want to send log messages to server log file without doing any change in log4j.config file.
-
3. Re: Logging
nickarls Nov 20, 2012 4:49 AM (in response to akash_bansal)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 Nov 20, 2012 5:00 AM (in response to nickarls)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 Nov 20, 2012 8:21 AM (in response to akash_bansal)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.