logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Deboy <scott.de...@gmail.com>
Subject Re: How do I hook in before log4j starts?
Date Mon, 18 Jul 2011 22:46:34 GMT
Can you lazily initialize the ref to the root logger in your
LoggerRepositoryHandler instead of passing it in to the constructor?  It
seems like that should resolve your problem.

Scott

On Mon, Jul 18, 2011 at 3:02 PM, Turner, Jay
<Jay.Turner@sabre-holdings.com>wrote:

> The inherited code did have some "public static final
> org.apache.log4j.Logger ..." calls, thank you. Changing those allowed my
> code to be called first. However a Catch-22 still exists. Trying:
>
>    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.
>
> I can't get ahold of the log4j system to link in my
> parseUnrecognizedElement method first without letting log4j setup everything
> first.
>
> How has anyone every hooked parseUnrecognizedElement into log4j before it
> starts up?
>
> I just need to process multiple non-logger/appender-specific myKey=myValue
> parameters like this:
>
>    <?xml version="1.0" encoding="UTF-8"?>
>    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>
>    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
> debug="true">
>
>        <param name="myKey" value="myValue"/>
>
> Thank you,
> Jay Turner
>
> > From: Scott Deboy ... more likely a static logger declaration or a logger
> instance
> > be initialized prior to your configuration code being ran.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message