You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Turner, Jay" <Ja...@sabre-holdings.com> on 2011/07/18 16:40:53 UTC

How do I hook in before log4j starts?

I want to be able to connect my new LoggerRepository to log4j before log4j runs its default initialization. But log4j seems to initialize before any significant code of mine is run. What causes the log4j initialization (statics?, get* calls?)? What can I execute before log4j initialization is triggered to hook in?

In detail, I have log4j.configuration=my.xml and log4j initializes with it. The issue is that I have created a new LoggerRepository that is the same as the base one but that implements UnrecognizedElementHandler. Now I want to hook that in so that log4j initialization uses my code while initializing. What happens right now is that I have to reinitialize again just to get the new elements. Without additivity=false there would be issues with duplicates, but initializing the system twice is inefficient and can cause other side effects.

Thank you,
Jay Turner


RE: How do I hook in before log4j starts?

Posted by "Turner, Jay" <Ja...@sabre-holdings.com>.
To add to the issue:

I can use log4j.defaultInitOverride and then my application gets control first. I can set log4j.configuratorClass and get control too. The issue is when my code is deployed in environments that already have log4j implementations. They may not set log4j.defaultInitOverride, and they certainly wouldn't set log4j.configuratorClass to my code. I can't change the system properties because that would affect other applications. I also cannot have my appenders, etc, placed in a central log4j XML configuration file. Each application must be able to be redeployed without interfering with others.

What I need is a way to set my configurator, logger repository, etc - not using system properties that can interfere with other applications - and then initialize log4j using my XML configuration which is not combined with any other.

Thank you,
Jay Turner

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


Re: How do I hook in before log4j starts?

Posted by Tushar Kapila <tg...@gmail.com>.
Can try - When your app start make sure the first class that runs does
not have a log4j instance member or other reference to log4j besides
the repository call. Use system out till then.

On 7/19/11, Turner, Jay <Ja...@sabre-holdings.com> wrote:
> I call my Library Jar which has log4j setup in it. I'm calling a static
> method in my class. Before I can get to the
> LogManager.setRepositorySelector, log4j gets to run, loads its configuration
> from log4j.configuration, can't interpret the unrecognized parameters, and
> generally finishes initialization. I suspect that when I enter the Library
> to run a static method that all of the other statics are run, along with the
> statics in log4j.jar. So log4j initializes before you can get a chance to
> setup anything. Unless I'm missing something, how can I get around this
> Catch-22?
>
> ---------------------------------------------------------------------
> 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


Re: How do I hook in before log4j starts?

Posted by Jacob Kjome <ho...@visi.com>.
Of course the quick fix is to manually set the "log4j.defaultInitOverride" 
property in code prior to calling LogManager.setRepositorySelector(rs,guard) 
using...

System.setProperty("log4j.defaultInitOverride", "true");

That way, you don't have to depend on a user setting it.


Jake


On Tue, 19 Jul 2011 14:58:49 -0500
 "Turner, Jay" <Ja...@sabre-holdings.com> wrote:
> 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
> 
> 


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


RE: How do I hook in before log4j starts?

Posted by "Turner, Jay" <Ja...@sabre-holdings.com>.
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


Re: How do I hook in before log4j starts?

Posted by Scott Deboy <sc...@gmail.com>.
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
>
>

RE: How do I hook in before log4j starts?

Posted by "Turner, Jay" <Ja...@sabre-holdings.com>.
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


Re: How do I hook in before log4j starts?

Posted by Scott Deboy <sc...@gmail.com>.
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
<Ja...@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
>
>

RE: How do I hook in before log4j starts?

Posted by "Turner, Jay" <Ja...@sabre-holdings.com>.
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


Re: How do I hook in before log4j starts?

Posted by Scott Deboy <sc...@gmail.com>.
log4j initialization is running because of explicit programmatic
configuration (via PropertyConfigurator/DOMConfigurator) or more likely a
static logger declaration or a logger instance be initialized prior to your
configuration code being ran.

I'd suggest changing your logger declarations to be non-static and moving
your initialization logic into a static block at the top of the first class
that is being loaded.

Scott

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

> I call my Library Jar which has log4j setup in it. I'm calling a static
> method in my class. Before I can get to the
> LogManager.setRepositorySelector, log4j gets to run, loads its configuration
> from log4j.configuration, can't interpret the unrecognized parameters, and
> generally finishes initialization. I suspect that when I enter the Library
> to run a static method that all of the other statics are run, along with the
> statics in log4j.jar. So log4j initializes before you can get a chance to
> setup anything. Unless I'm missing something, how can I get around this
> Catch-22?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

RE: How do I hook in before log4j starts?

Posted by "Turner, Jay" <Ja...@sabre-holdings.com>.
I call my Library Jar which has log4j setup in it. I'm calling a static method in my class. Before I can get to the LogManager.setRepositorySelector, log4j gets to run, loads its configuration from log4j.configuration, can't interpret the unrecognized parameters, and generally finishes initialization. I suspect that when I enter the Library to run a static method that all of the other statics are run, along with the statics in log4j.jar. So log4j initializes before you can get a chance to setup anything. Unless I'm missing something, how can I get around this Catch-22?

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