logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Turner, Jay" <Jay.Tur...@sabre-holdings.com>
Subject RE: How do I hook in before log4j starts?
Date Tue, 19 Jul 2011 19:58:49 GMT
I don't know how to submit a bug or a patch.

I think the design just needs a little ... flexibility. Keep everything the same but provide
an entry point or two that set things before configuring. The entire static block probably
needs to be a method that is guarded and invoked once. Then a few static method can set things
before the other static methods check the guard and configure when needed.

I'll look at it and anyone feel free to take a stab at it too.

Thank you,
Jay Turner

-----Original Message-----
From: Scott Deboy [mailto:scott.deboy@gmail.com] 
Sent: Tuesday, July 19, 2011 2:22 PM
To: Log4J Users List
Subject: Re: How do I hook in before log4j starts?

That sounds like a bug that should be fixed.  Mind submitting a bug?  If you
want to provide a patch we'd be happy to review it.

Thanks

Scott

On Tue, Jul 19, 2011 at 12:18 PM, Turner, Jay <Jay.Turner@sabre-holdings.com
> wrote:

> I can do some lazy initialization, but there is still a basic problem.
>
> Looking at the source code for LogManager, I find that it has a static
> block of code. This static block will run as I try to do anything with
> LogManager. I can get it down to LogManager.setRepositorySelector(rs,guard)
> without trigerring the static block in LogManager. The mere call to
> setRepositorySelector runs the static block first, which runs code that
> calls OptionConverter.selectAndConfigure(...) unless
> log4j.defaultInitOverride is set.
>
> So there is no way to prepare log4j before it initializes unless the user
> is kind enough to set log4j.defaultInitOverride or define
> log4j.configuratorClass. Both of these require the user - instead of the
> library handling the logging on behalf of the user - to setup the
> environment correctly and without conflicting with any other application.
>
> Thank you,
> Jay Turner
>
> -----Original Message-----
> From: Scott Deboy [mailto:scott.deboy@gmail.com]
> Sent: Monday, July 18, 2011 5:47 PM
> To: Log4J Users List
> Subject: Re: How do I hook in before log4j starts?
>
> 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-holdin gs.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
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message