Friday, 10 February 2012

Configure log4j in Weblogic10.3

For Configuring log4j in Weblogic 10.3 follow below steps:

1) Place log4j-1.2.16.jar in your project build path.

2) put log4j.xml in your domain directory ( you can make any folder for ex. 'configuration')

3) There are many ways to initilize log4j, here I am including two ways

  a) Edit the server start up script
     Open $DOMAIN_HOME\bin\setDomainEnv.cmd and set LOG4J_CONFIG_FILE with complete path of log4j.xml. For example if you have placed log4j.xml under configuration folder.
set LOG4J_CONFIG_FILE=%DOMAIN_HOME%\configuration\log4j.xml

b) With Spring framework 
If you are using Spring framework in your application then add below entry in web.xml.
    <context-param>
   <param-name>log4jConfigLocation</param-name>
   <param-value>file:${DOMAIN_HOME}/configuration/log4j.xml</param-value>
 </context-param>
 <context-param>
   <param-name>log4jExposeWebAppRoot</param-name>
   <param-value>false</param-value>
 </context-param>
 <listener>
   <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>

4) Restart the server.

You are done with log4j configuration !!

2 comments:

  1. Nice post. This realy help me to setup log4j in my project. Please continue good work.


    Regards,
    Arun

    ReplyDelete
  2. Heyyy!! Many Thanks for sharing this ... Now am able to configure log4j in weblogic portal .... :)

    ReplyDelete