Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Best Approach for using Log4j inside a Servlet

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning log4j The code below uses DOMConfigurator.configure(propfile);



Please guide me what is the best place to perform this operation ? Should i perform this using Listener Or with Start up normal Servlet
So that the other parts of the Application can also use it with simply calling statis method
getLogger directly and use it .
 
Bartender
Posts: 4106
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using initialization servlet is more flexible in a web application. Different ways of initializing are explained here.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Vijitha .

I follow the approach of using Servlet only for Log4J initilization .

My question now is that how can " other parts of the Application can also use this log4j configuration "



I mean how can i use

Assume MyClass is class inside a Application . How can it use this statement .

Please share your ideas . Thanks in advance



 
Vijitha Kumara
Bartender
Posts: 4106
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ravi Pavan wrote:I mean how can i use

Assume MyClass is class inside a Application . How can it use this statement .



Just initialize the logger (with static modifier) inside the class you want to use it like you have mentioned.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You . So i think that Framework takes this responsibility.
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!