Monday 6 July 2009

Logging and Properties in Weblogic

I was busy with developing a webservice to be deployed on Websphere. In fact it is the same service that brought me to get introduced in Sun's Metro & Glassfish. It's going to get a list of tasks for a user out of BPM Suite. So maybe I write an article soon about that too.

About deploying a Metro-webservice to Weblogic I wrote this article. But the webservice needs a configuration file with properties related to connecting to BPM-Suite. And I use log4j as a logging framework and it would be helpfull to see my webservice's logging in Weblogic too.

Properties
For getting the property file read within weblogic there are several options. But the best one is to get it loaded from the classpath. Having it loaded as a FileInputStream is not handy, because you need an absolute or relative path to the file. Absolute is not handy because puts strict constraints on the location of the file. A relative path is better, but with a application server you probably don't know from which base-folder it is started. So a classpath location is better. I used a propertyloader that is described here.
It turns out that root folder of the Weblogic domain you're running is a proper place to locate your property file. But you could extend the classpath with the domain's-config folder.
Changing the classpath can be done in the setDomainEnv.cmd (Windows) or setDomainEnv.sh (Unix/Linux) scripts. Look for "SET THE CLASSPATH". The classpath is build up from different pieces. You can edit the pieces earlier in the script or the classpath setting itsself, depending on what you find the proper place.

Log4J
Weblogic 10.3 by default makes use of JDK based logging. To use Log4J you need to do several steps:
  • Add log4j libraries: put the log4j-1.2.15.jar (got it from an Apache Axis distribution, but you can also download it directly from Apache) in the *weblogic-domain-home*/lib folder.
  • Add weblogic wllog4j.jar from *weblogic-server-home*\server\lib\ to the *weblogic-domain-home*/lib folder. (otherwise you get the error: java.lang.ClassNotFoundException: weblogic.logging.log4j.JDKLog4jAdapterFactory
  • Set log4j-logging in Weblogic, following this doc.
  • You can also add the property -Dweblogic.log.Log4jLoggingEnabled=true to the 'set JAVA_PROPERTIES' line in the setDomainEnv script.
  • Then you might want to have your own log4j.properties file loaded. That is possible by setting the environment variable LOG4J_CONFIG_FILE to the location of your property file.
Restart your weblogic domain to get the settings effective. w

10 comments :

Chris said...

Very helpful, thank you.

wing said...

Hi ,

I have tried your solution, but i still dont see the custom application log produced by log4j in the administration console.... do you know what i did wrong... or is it just impossible.... does the log need to be in a specific weblogic format?

Thanks in advance,
Wing

Martien van den Akker said...

Hi,

I think you should try the log4j settings. Having at least or maybe only a file appender for your classes. I had to play around for that.
The file should be on the filesystem where you denoted it in the log4j.properties.

Regards,
Martien

wing said...

Hi Martien,

Thanks for the reply. Actually I do see the log file but i cant seem to get it viewable in the weblogic administration console. I dont want to have developers login to the server in order to view this file. Thats the reason why i want it to be viewable through the console.

I cant seem to be able to get this last part done. Any ideas or suggestions?

Thanks in advance,
Wing

Martien van den Akker said...

Sorry, I did not get that far. I was happy enough that I got the logs anyway. I used the weblogic as a developers server. The webservice had to be deployed on Websphere.

Regards,
Martien

Unknown said...

This was very helpful. Thank you very much for the

Unknown said...

Thank you very much. This did the trick for me!

Anonymous said...

Thanks so much! You saved my day

Unknown said...

Hi, The post is very much helpful. Will this is possible in BPM 12c as well?? Please assist me.

Anonymous said...

Hi,

It should be, since BPM 12c runs on Weblogic12c. See also https://community.oracle.com/thread/4007736.