aspose file tools*
The moose likes Websphere and the fly likes Log4j in websphere Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Log4j in websphere" Watch "Log4j in websphere" New topic
Author

Log4j in websphere

DeepakN kumar
Greenhorn

Joined: Apr 14, 2012
Posts: 27
Hi,

Can any one please tell whether in need to explicitly initialize the Log4j in the below way using java code in an J2EE application or Websphere internally initialize Log4j?

Please note that i am configuring log4j.xml as a system property.

<code>
URL configFileResource = ServletKara.class.getResource(getInitParameter("logconfig"));
DOMConfigurator.configure(configFileResource);
</code>
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Just to clarify: you want your web application to use log4j for logging, correct? And you aren't trying to get Websphere itself to write all of its logs via log4j?

In this case all you need to do is to put the log4j jar file into your application's WEB-INF/lib directory and the log4j.xml file in the WEB-INF/classes directory. No need for system properties. No need for any code to initialize log4j, either, that happens automatically.
DeepakN kumar
Greenhorn

Joined: Apr 14, 2012
Posts: 27
Thanks . Yes i want my web application to use Log4j and NOT trying to get Websphere to write logs.

I have one more question here. When you say log4j initialization happens automatically, does that mean that Websphere initializes log4j using the DOMConfigurator.configure()? OR log4j internally does this for us?

Also when exactly do we use DOMConfigurator.configure() ? when log4j.xml(or log4j.properties) not available in classpath?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

DeepakN kumar wrote:I have one more question here. When you say log4j initialization happens automatically, does that mean that Websphere initializes log4j using the DOMConfigurator.configure()? OR log4j internally does this for us?


log4j automatically initializes itself the first time you call it. It looks for log4j.properties or log4j.xml in the classpath. Websphere has nothing to do with any of this.

Also when exactly do we use DOMConfigurator.configure() ? when log4j.xml(or log4j.properties) not available in classpath?


Well, looking at the API docs I see that you can configure from a DOM Element object. And I suppose people might have a good reason why they want their log4j properties to be somewhere else instead of putting them in the web application... maybe they want to be able to fiddle with it and not have to redeploy the web app? Really it's anybody's guess. (And if you think there's an "exact" answer to this question, when you get a bit more experience you'll see how silly that sounds.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log4j in websphere