Sunday, 13 February 2011

Adding Log4j to a Weblogic Domain Configuration

One of the things I often have to do is install Weblogic Server for development purposes, which often means making manual changes to an installation created by the install wizard and the way to do this is to modify the setDomainEnv file. There are two copies of this for every Weblogic installation: one for Windows, and the other for Unix. Given that I generally do most development under Windows, then I’ll be using setDomainEnv.cmd in this example, which demonstrates how to add log4j to the installation.

The first thing to do is to turn off production mode:
... this is a ‘global’ variable, which sets the following four variables:
set debugFlag=true
 set testConsoleFlag=true
 set iterativeDevFlag=true
 set logErrorsToConsoleFlag=true
The next step is to define the location of your ‘’ file.
set LOG4J_CONFIG_FILE=%DOMAIN_HOME%/config/log4j/

if NOT "%LOG4J_CONFIG_FILE%"=="" (
    set JAVA_PROPERTIES=%JAVA_PROPERTIES% -Dlog4j.configuration=file:%LOG4J_CONFIG_FILE%
Weblogic also needs to know where to find the log4j jar file by adding it to the EXT_PRE_CLASSPATH:
set %EXT_POST_CLASSPATH%=%DOMAIN_HOME%/lib/log4j-1.2.9.jar
This small config file change has been tested on BEA's Weblogic 6 right up to Oracle's Weblogic 11g (10.3.2).

There are many other ad-hoc changes you can make to this file; this blog has just outlined one of those.

No comments: