This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Best Practice to load log4j in servlet app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Best Practice to load log4j in servlet app" Watch "Best Practice to load log4j in servlet app" New topic
Author

Best Practice to load log4j in servlet app

Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
I have very little application which consists of 2 servlets. I have placed the log4j.properties file in classes folder. I need to know what would be the best practice and how should configure the log4j logger for my application.

Currently i am using this approach



The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
I normally write a class which implements ServletContextListener. You can check this example. I load log4j config in contextInitialized.

Also cleaner way of loading log4j config



SCJP 1.4
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

Log4j should find it if the configuration file is in the root of the classpath (WEB-INF/classes for a web application). Have a look at the Short Introduction to Log4j and scroll down to the section titled "Default Initialization Procedure" and "Default Initialization under Tomcat".


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
Joe Ess wrote:Log4j should find it if the configuration file is in the root of the classpath (WEB-INF/classes for a web application). Have a look at the Short Introduction to Log4j and scroll down to the section titled "Default Initialization Procedure" and "Default Initialization under Tomcat".

emm .. that's nice one. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best Practice to load log4j in servlet app
 
Similar Threads
Logging in struts
where to put log4j.properties file in visual web jsf
How do I initialise a servlet ?
where to put log4j.properties?
thread safe logging in a servlet