aspose file tools
The moose likes IDEs, Version Control and other tools and the fly likes Log4J - When to configure? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Reply Bookmark "Log4J - When to configure?" Watch "Log4J - When to configure?" New topic
Author

Log4J - When to configure?

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

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.


My Blog: Down Home Country Coding with Scott Selikoff
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

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?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Log4J - When to configure?
 
Similar Threads
log4j - new instance for new class instance
How to encapsulate Logger info
Log4J configuration problem
Initializing log4j within Eclipse on a per project (Dynamic Web Project) basis
Why do we need mulitple loggers? - Log4j