https://issues.apache.org/bugzilla/show_bug.cgi?id=51651
Jay Turner <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- URL| |http://mail-archives.apache | |.org/mod_mbox/logging-log4j | |-user/201107.mbox/%3cEE0D7A | |B02A80D4459912838AFB3F3E4C4 | |[email protected]. | |ad.sabre.com%3e --- Comment #1 from Jay Turner <[email protected]> 2011-08-11 18:59:10 UTC --- log4j runs the static block of code in LogManager, which initializes all of log4j, before a user can setup their own configuration. The user cannot set an UnrecognizedElementHandler or call setRepositoryHandler based off of the default repository without log4j initializing before the customizations are made. Consider: private static final Object guard = new Object(); private static final LoggerRepositoryHandler handler = setupLoggerRepositoryHandler(); private static LoggerRepositoryHandler setupLoggerRepositoryHandler() { LoggerRepositoryHandler handle = new LoggerRepositoryHandler(org.apache.log4j.LogManager.getLoggerRepository().getRootLogger()); org.apache.log4j.LogManager.setRepositorySelector(new RepositorySelector() { public LoggerRepository getLoggerRepository() { return handler; }}, guard ); return handle; } This gets called first, but the org.apache.log4j.LogManager.getLoggerRepository() call to link my repository with the default repository invokes the log4j setup, which completes and uses the default repository before my new repository (with the parseUnrecognizedElement method) is setup. If I set the selector first then when I call getLoggerRepository() it will go through my selector which has no default repository setup. Lazily calling setLoggerRepository doesn't work because the first reference into log4j initializes everything before returning. A possible solution is to have setters like setUnrecognizedElementHandler(). Another is to have statics that set options and have the static block in LogManager be called through a guarded init() call. -- Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
