Saturday, March 12, 2016

Configuring log4j on weblogic server for web applications.

To configure Weblogic server :
  • Go to WL_HOME/server/lib and copy wllog4j.jar to the server CLASSPATH, to do this copy the file into DOMAIN_NAME/lib
  • Download log4j jar (in my case I had not the file) from http://logging.apache.org/log4j/1.2/download.html , in this case the last available version is log4j-1.2.17.jar, and copy the file into DOMAIN_NAME/lib (As step 2).
  • In this case I activate log4j using WLST (Weblogic Scripting Tool), as bellow :
  • As you're using windows, execute a terminal window and go to DOMAIN_NAME/bin and run the file setDomainEnv.cmd (this file will set the environment to run java).
  • Execute the following comands :

                                        C:\>java weblogic.WLST
                                       wls:/offline> connect('username','password')
                                       wls:/mydomain/serverConfig> edit()
                                       wls:/mydomain/edit> startEdit()
                                       wls:/mydomain/edit !> cd("Servers/$YOUR_SERVER_NAME/Log/$YOUR_SERVER_NAME";)
                                       wls:/mydomain/edit/Servers/myserver/Log/myserver !> cmo.setLog4jLoggingEnabled(true)
                                       wls:/mydomain/edit/Servers/myserver/Log/myserver !> save()
                                       wls:/mydomain/edit/Servers/myserver/Log/myserver !> activate()
  • Use ls() to list the objects under the WLS directory
  • This will activate log4j to use it with WLS.


To configure applications :
  • Create a log4j.properties file as bellow

                                  log4j.debug=TRUE
                                  log4j.rootLogger=INFO, R
                                  log4j.appender.R=org.apache.log4j.RollingFileAppender
                                  log4j.appender.R.File=/home/server.log
                                  log4j.appender.R.MaxFileSize=100KB
                                  log4j.appender.R.MaxBackupIndex=5
                                  log4j.appender.R.layout=org.apache.log4j.PatternLayout
                                  log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSSS} %p %t %c – %m%n
  • Copy the file to /WEB-INF/classes directory. of your application.
  • Implement also the last action provided to activate log4j on WLS


No comments:

Post a Comment