开发者

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

开发者 https://www.devze.com 2022-12-17 22:32 出处:网络
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.

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 开发者_Go百科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


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


To my knowledge, you can't (and no, you don't want to) change WebLogic Server's own Log Message Format (the support will be very happy to have the required informations in case of a problem).

But you can configure WebLogic to use Log4j (see How to Use Log4j with WebLogic Logging Services) and, when Log4j is enabled, you can get a reference to the org.apache.log4j.Logger that the server is using and attach your own appender.

When Log4j is enabled, you get a reference to the org.apache.log4j.Logger that the server is using from the weblogic.logging.log4j.Log4jLoggingHelper class.

With a Log4j Logger reference, you can attach you own custom appender to receive the server log events; for example, you might attach an appender that sends the server log events to Syslog or the Windows Event Viewer. Additionally, you can use the Logger reference to issue log requests to WebLogic logging services; this requires that the Log4j libraries be available to your deployed application.

But this is not a replacement of WebLogic's own log.


I have no desire to replace WebLogic's logger, but I do have a very strong desire to configure the log format. The method Amnon posted works very well (so I'm not sure why you say you can't change the format); I'd just like some additional detail.

About the only negative I see with the method is that, if you have StdOut/StdErr redirected to the logging subsystem, it shows up in the log with an empty value for the %c conversion character; if I don't change the layout pattern then I see and instead.

That is what I wanted to see the original pattern layout string, so I could make my changes and keep in the logfile.


The posts so far did not answer the original question, which is why WebLogic does not pick up the desired log format configured in log4j.properties file.

It sounds to me that you are using WL's Server Logging Bridge to redirect application's log4j's messages to the WL server's logging services? If this assumption is correct, from Configuring Log Files and Filtering Log Messages for Oracle WebLogic Server, you would need to pass an argument in the WL server's startup command, to load the correct log4j configurations,

-Djava.util.logging.config.file=/[PATH]/log4j.properties

Cleaner just pass this JVM option when you launch WL, though alternatively you can achieve it programmingly as in the previous post.


Weblogic is not picking up your log4j.properties because its does not know that there is one.

You need to go to server's classpath and append the path to properties file, save changes and restart your server. It should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消