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 Gaurav Arora <ga...@newgen.co.in> on 2007/02/16 10:16:33 UTC

Changing / Retrieving log4j config at runtime

Hi,
    I have been trying to retrieve all loggers attached to a root log 
using a servlet that runs at server startup but I haven't been able to 
do so yet. I tried using the getAllAppenders method, which the manual 
says is deprecated and the Hierarchy class as well, both don't seem to 
work. What I am trying to do is, get a list of all loggers and appenders 
attached to them on server startup and dump them in a more user friendly 
view. Have I been doing it the wrong way? Is there a better way to do 
the above?

I'm using version 1.2.14 and Tomcat 5.5.

Thanks,
Gaurav


Disclaimer :- This e-mail message including any attachment may contain confidential, proprietary or legally privileged information. It should not be used by who is not the original intended recipient. If you have erroneously received this message, you are notified that you are strictly prohibited from using, copying, altering or disclosing the content of this message. Please delete it immediately and notify the sender. Newgen Software Technologies Ltd and / or its subsidiary Companies accept no responsibility for loss or damage arising from the use of the information transmitted by this email including damage from virus and further acknowledges that any views expressed in this message are those of the individual sender and no binding nature of the message shall be implied or assumed unless the sender does so expressly with due authority of Newgen Software Technologies Ltd and / or its subsidiary Companies, as applicable.


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


Re: Changing / Retrieving log4j config at runtime

Posted by zeusfaber <ze...@gmail.com>.


Curt Arnold wrote:
> 
> A null return from Logger.getLevel() indicates that logger does not  
> have an explicit level, but inherits a level from its parent or their  
> parents.  If you return the parent's level in this situation, you can  
> no longer distinguish between a logger who has a level of its own and  
> should not be affected by a change of its parent's level and a logger  
> which has no level of its own and should be affected by a change of  
> its parent's level.
> 

It was the only solution I found to solve it.
Actually in my log4j.xml this loggers are defined as:

   <logger name="ExitProcess_9901" additivity="false">
        <level value="DEBUG"/>
        <appender-ref ref="EXIT_1"/>
   </logger>

   <logger name="ErrorProcess_6601" additivity="false">
        <level value="DEBUG"/>
        <appender-ref ref="ERROR_1"/>
   </logger>

So all my levels are explicit.

Bye 

--
Davide
-- 
View this message in context: http://www.nabble.com/Changing---Retrieving-log4j-config-at-runtime-tf3238396.html#a9007161
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: Changing / Retrieving log4j config at runtime

Posted by Curt Arnold <ca...@apache.org>.
On Feb 16, 2007, at 9:43 AM, zeusfaber wrote:
> Any idea where I'm wrong?
>
> Thank you in advance
>
> --
> Davide
>


A null return from Logger.getLevel() indicates that logger does not  
have an explicit level, but inherits a level from its parent or their  
parents.  If you return the parent's level in this situation, you can  
no longer distinguish between a logger who has a level of its own and  
should not be affected by a change of its parent's level and a logger  
which has no level of its own and should be affected by a change of  
its parent's level.



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


Re: Changing / Retrieving log4j config at runtime

Posted by James Stauffer <st...@gmail.com>.
I don't know if this would work but you could try recursing the logger
tree removing all appenders and reseting all levels before calling
configure.

On 2/16/07, zeusfaber <ze...@gmail.com> wrote:
>
>
>
> James Stauffer wrote:
> >
> > For one thing, DOMConfigurator.configure adds to the current config --
> > it doesn't replace it.  Thay is why some loggers still see the changed
> > configuration.
> >
>
> Thank you James for you prompt reply.
> Hummm,
> this could be the reason I'm seeing strange behaviours.
> But so, what would be the correct procedure to reload programmatically the
> old configuration without restarting the application?
> I found no evidence in the complete manual too :-)
>
> bye
>
> --
> Davide
> --
> View this message in context: http://www.nabble.com/Changing---Retrieving-log4j-config-at-runtime-tf3238396.html#a9007011
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

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


Re: Changing / Retrieving log4j config at runtime

Posted by zeusfaber <ze...@gmail.com>.


James Stauffer wrote:
> 
> For one thing, DOMConfigurator.configure adds to the current config --
> it doesn't replace it.  Thay is why some loggers still see the changed
> configuration.
> 

Thank you James for you prompt reply.
Hummm,
this could be the reason I'm seeing strange behaviours.
But so, what would be the correct procedure to reload programmatically the
old configuration without restarting the application?
I found no evidence in the complete manual too :-)

bye

--
Davide
-- 
View this message in context: http://www.nabble.com/Changing---Retrieving-log4j-config-at-runtime-tf3238396.html#a9007011
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: Changing / Retrieving log4j config at runtime

Posted by James Stauffer <st...@gmail.com>.
For one thing, DOMConfigurator.configure adds to the current config --
it doesn't replace it.  Thay is why some loggers still see the changed
configuration.

On 2/16/07, zeusfaber <ze...@gmail.com> wrote:
>
> Maybe this is the correct thread ;-)
>
> In my application I'm changing and retrieving programmatically logger levels
> via the:
>
> logger.setLevel(...) /getLevel()
>
> Then I though to add a "restore defaults" feature that reloads the original
> configuration through:
>
> DOMConfigurator.configure(xmlFilePath);
>
> Now I' m having problems becouse, *sometimes* *some* loggers still see the
> changed configuration.
>
> Sometimes the logger.getLevel() reutrn null so I added a check:
>
> Level level = loggerInstance.getLevel();
>
> if (level == null)
> {
>   Logger root = Logger.getRootLogger();
>   return root.getLevel().toInt();
> }
>
> return level.toInt();
>
> Any idea where I'm wrong?
>
> Thank you in advance
>
> --
> Davide
>
>
>
> --
> View this message in context: http://www.nabble.com/Changing---Retrieving-log4j-config-at-runtime-tf3238396.html#a9006677
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

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


Re: Changing / Retrieving log4j config at runtime

Posted by zeusfaber <ze...@gmail.com>.
Maybe this is the correct thread ;-)

In my application I'm changing and retrieving programmatically logger levels
via the:

logger.setLevel(...) /getLevel()

Then I though to add a "restore defaults" feature that reloads the original
configuration through:

DOMConfigurator.configure(xmlFilePath);

Now I' m having problems becouse, *sometimes* *some* loggers still see the
changed configuration.

Sometimes the logger.getLevel() reutrn null so I added a check:

Level level = loggerInstance.getLevel();

if (level == null)
{
  Logger root = Logger.getRootLogger();
  return root.getLevel().toInt();
}

return level.toInt();

Any idea where I'm wrong?

Thank you in advance

--
Davide



-- 
View this message in context: http://www.nabble.com/Changing---Retrieving-log4j-config-at-runtime-tf3238396.html#a9006677
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: Changing / Retrieving log4j config at runtime

Posted by James Stauffer <st...@gmail.com>.
Look for LogWeb it is a servlet that allows configuring log4j.  It
will either meet your needs or show you how to do what you want to do.

On 2/16/07, Gaurav Arora <ga...@newgen.co.in> wrote:
> Hi,
>     I have been trying to retrieve all loggers attached to a root log
> using a servlet that runs at server startup but I haven't been able to
> do so yet. I tried using the getAllAppenders method, which the manual
> says is deprecated and the Hierarchy class as well, both don't seem to
> work. What I am trying to do is, get a list of all loggers and appenders
> attached to them on server startup and dump them in a more user friendly
> view. Have I been doing it the wrong way? Is there a better way to do
> the above?
>
> I'm using version 1.2.14 and Tomcat 5.5.
>
> Thanks,
> Gaurav
>
>
> Disclaimer :- This e-mail message including any attachment may contain confidential, proprietary or legally privileged information. It should not be used by who is not the original intended recipient. If you have erroneously received this message, you are notified that you are strictly prohibited from using, copying, altering or disclosing the content of this message. Please delete it immediately and notify the sender. Newgen Software Technologies Ltd and / or its subsidiary Companies accept no responsibility for loss or damage arising from the use of the information transmitted by this email including damage from virus and further acknowledges that any views expressed in this message are those of the individual sender and no binding nature of the message shall be implied or assumed unless the sender does so expressly with due authority of Newgen Software Technologies Ltd and / or its subsidiary Companies, as applicable.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

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