• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Best Practice to load log4j in servlet app

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
It's a tiny ad. At least, that's what she said.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic