• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Log4J - When to configure?

 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each class in my project establishes a logger with the call:



I'd like to configure the Log4J using the call with:



Question, when should this call be made? Is the order that it happens relevant to when Logger.getLoger() is called?

The reason I ask is the pattern used in my code wraps Logger.getLogger(...) in a helper class that calls DOMConfigurator.configure(...) each time the Logger.getLogger(...) and I think I'm hitting an intermittent concurrency issue of some kind from the frequent calls to configure made by each class as it instatiates. The logger start ups fine, but stops writing to disk early in the startup process. A subsequent call to DOMConfigurator.configure() can reestablish the logger writing ability, but I'd like to know why it sometimes loses the ability to write to disk on startup.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind about the concurrency issue, found the cause, still not sure when configure() should be called. Before any loggers initialize, after, or does it not really matter?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Call it as soon as possible. Log4j will initialize itself as soon as it can, i.e. as soon as you first do that. It isn't possible for you to do that before log4j's initialization.
 
reply
    Bookmark Topic Watch Topic
  • New Topic