How to change Weblogic 10/11's log format?

tippytai picture tippytai · Jan 21, 2010 · Viewed 9.1k times · Source

I want to change the log format for Weblogic's server log. Right now it's generating logs using its default format-- I want to be able to specify my own format.

For example, it generates logs that look like this:

####<Jan 21, 2010 3:24:24 PM EST> <Info> <Socket> <FS2LOANER-00981> <DPSCoreServer1> <[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1264105464314> <BEA-000436> <Allocating 2 reader threads.> 
####<Jan 21, 2010 3:24:24 PM EST> <Info> <Socket> <FS2LOANER-00981> <DPSCoreServer1> <[STANDBY] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1264105464314> <BEA-000446> <Native IO Enabled.> 

I have tried to modify the log format by having Weblogic use LOG4J as its logging system and having it use my log4j.properties file which defines my desired log formats. However, weblogic does not pick up my log4j.property file settings and continues to log in its desired format, regardless of what I try.

This is effectively a very similar question to the following post, but that question never really got answered (the approved answer was regarding how to turn on log4j debugging, which hasn't helped me figure out why weblogic is not picking up my log4j.properties file). Using log4j logging in weblogic 9/10

Answer

Amnon Grossman picture Amnon Grossman · Dec 2, 2010

Create a domain startup class as follows:

import org.apache.log4j.PatternLayout;

import weblogic.logging.LoggerNotAvailableException;
import weblogic.logging.log4j.Log4jLoggingHelper;

public class LoggingConfigurator {
    public static void main(String[] args) {
        try {
            System.out.println("Configuring Log4j pattern");
            Log4jLoggingHelper.getLog4jServerLogger().getAppender("WLLog4jRotatingFileAppender")
                    .setLayout(new PatternLayout("%d{ISO8601} %-5p [%c] - %m%n"));
        } catch (LoggerNotAvailableException e) {
            e.printStackTrace();
        }
    }
}

Amnon