logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 51651] Hook in before log4j starts, e.g. UnrecognizedElementHandler
Date Thu, 11 Aug 2011 18:59:10 GMT

Jay Turner <jay.turner@sabre.com> changed:

           What    |Removed                     |Added
                URL|                            |http://mail-archives.apache
                   |                            |.org/mod_mbox/logging-log4j
                   |                            |-user/201107.mbox/%3cEE0D7A
                   |                            |B02A80D4459912838AFB3F3E4C4
                   |                            |F6C3D16@SGTULMMP002.Global.
                   |                            |ad.sabre.com%3e

--- Comment #1 from Jay Turner <jay.turner@sabre.com> 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 =

private static LoggerRepositoryHandler setupLoggerRepositoryHandler() {
    LoggerRepositoryHandler handle = new

    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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message