You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2011/08/11 20:24:58 UTC

DO NOT REPLY [Bug 51651] New: Hook in before log4j starts, e.g. UnrecognizedElementHandler

https://issues.apache.org/bugzilla/show_bug.cgi?id=51651

             Bug #: 51651
           Summary: Hook in before log4j starts, e.g.
                    UnrecognizedElementHandler
           Product: Log4j
           Version: 1.2
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Configurator
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: jay.turner@sabre.com
    Classification: Unclassified


-- 
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


DO NOT REPLY [Bug 51651] Hook in before log4j starts, e.g. UnrecognizedElementHandler

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51651

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