Using log4j logging in weblogic 9/10

In weblogic, I can configure the console so that Serverlog uses log4j instead of registering the default JDK.

However, the server log does not use the log4j.properties file, but it seems to use the configuration in config.xml even if the log4j.properties file is in the class path, and I set these properties:

set JAVA_OPTIONS=%JAVA_OPTIONS% -Dlog4j.configuration=file:<path>/log4j.properties
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger   
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dweblogic.log.Log4jLoggingEnabled=true 

Is it possible to use the log4j.properties configuration for logging Weblogic Server or can I change the log4j configuration using java code?

+5
source share
5 answers

WebLogic, -Dlog4j.debug , log4j , . , , tomcat.

PropertyConfigurator DOMConfigurator log4j.

+6

log4j.xml , WebLogic . Apache Commons log4j WebLogic, . Java.

0

? -Dlog4j , log4j

0

Log4j Logger Java:

* When you start the Administration Server, include the following Java option in the weblogic.Server command:

  -Dweblogic.log.Log4jLoggingEnabled=true 

: http://edocs.bea.com/wls/docs103/logging/config_logs.html#wp1014610

0

I never got this job as I expected.

In the end, I created some kind of work. I am logging a handler that listens to the Weblogic server log. From this handler I register log4j myself. This journal can be redirected to do whatever I want.

create your own logHandler:

public class CustomLogHandler extends Handler {
..

    public CustomLogHandler () throws SecurityException, IOException,
            NamingException {

        String log4jConfig = LogFilterConfiguration.getLog4jDirectory();
        classlogger.info("log4j configured for file"+ log4jConfig );
        PropertyConfigurator.configure(log4jConfig);
        logFilterConfiguration = new LogFilterConfiguration();
    }

    public void publish(LogRecord record) {
        WLLogRecord rec = (WLLogRecord) record;
        if (!isLoggable(rec))
            return;
        if (getLoggerName().. is something i want to log) {
                        // do my own log4j logging
                  }

then create an ApplicationLifecycleListener. with postStart method:

public void postStart(ApplicationLifecycleEvent evt) {
    Logger logger = LoggingHelper.getServerLogger();
    Handler oldHandler = null;
    Handler[] currentHandlers = logger.getHandlers();

              .. code to remove an old custom handler if exists...
    with something like logger.removeHandler(oldHandler);

    // add custom handler to serverlogger.
    CustomLogHandler h = null;      
    try {
        h = new CustomLogHandler ();
        // If handler was removed we can add a new version.
        if (!(unRemovedHandlerClasses.contains(h.getClass()))){
            logger.addHandler(h);
            registerMBean(h) ;
        }
    } catch (Exception nmex) {
    classLogger.error("Error adding CustomLogHandler to serverlogger "
                + nmex.getMessage());
        logger.removeHandler(h);
    }


}
0
source

All Articles