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 Karl Kildén <ka...@gmail.com> on 2014/05/12 22:02:19 UTC

Fwd: Log4J2 - Set log level programmatically

Hi!

Reading this
http://mail-archives.apache.org/mod_mbox/logging-log4j-user/201305.mbox/%3CBAF05689-F627-457D-BD37-59BFCE46F69E@nicholaswilliams.net%3E

hints that this is fully possible. This is also a very nice feature for
webapps (especially those running in a cluster) because editing a file on
the server is error prone and sometimes not even possible.

The docs for log4j2 is pretty great overall but I would really like some
info on setting the levels programmatically...

Thanks for log4j, a staple framework I use for every project :-) Time to
upgrade to log4j2 (hence the question)

cheers

Re: Log4J2 - Set log level programmatically

Posted by Karl Kildén <ka...@gmail.com>.
Hi Ralph,

Thanks a lot.




On 12 May 2014 23:23, Ralph Goers <ra...@dslextreme.com> wrote:

> There are two ways to do it.
>
> 1. Use JMX. There you would get access to the MBean and then call the
> appropriate method.  I haven’t checked to see if that code is doing it
> correctly though.
> 2. See
> https://svn.apache.org/repos/asf/logging/log4j/log4j2/trunk/src/site/xdoc/manual/customconfig.xml.
> Unfortunately that page has not been published to the site yet.  To set the
> level just get the LoggerConfig you want, change its level and then call
> updateLoggers on the LoggerContext.
>
> Ralph
>
>
> On May 12, 2014, at 1:02 PM, Karl Kildén <ka...@gmail.com> wrote:
>
> > Hi!
> >
> > Reading this
> >
> http://mail-archives.apache.org/mod_mbox/logging-log4j-user/201305.mbox/%3CBAF05689-F627-457D-BD37-59BFCE46F69E@nicholaswilliams.net%3E
> >
> > hints that this is fully possible. This is also a very nice feature for
> > webapps (especially those running in a cluster) because editing a file on
> > the server is error prone and sometimes not even possible.
> >
> > The docs for log4j2 is pretty great overall but I would really like some
> > info on setting the levels programmatically...
> >
> > Thanks for log4j, a staple framework I use for every project :-) Time to
> > upgrade to log4j2 (hence the question)
> >
> > cheers
>
>

Re: Log4J2 - Set log level programmatically

Posted by Ralph Goers <ra...@dslextreme.com>.
There are two ways to do it. 

1. Use JMX. There you would get access to the MBean and then call the appropriate method.  I haven’t checked to see if that code is doing it correctly though.
2. See https://svn.apache.org/repos/asf/logging/log4j/log4j2/trunk/src/site/xdoc/manual/customconfig.xml. Unfortunately that page has not been published to the site yet.  To set the level just get the LoggerConfig you want, change its level and then call updateLoggers on the LoggerContext.

Ralph


On May 12, 2014, at 1:02 PM, Karl Kildén <ka...@gmail.com> wrote:

> Hi!
> 
> Reading this
> http://mail-archives.apache.org/mod_mbox/logging-log4j-user/201305.mbox/%3CBAF05689-F627-457D-BD37-59BFCE46F69E@nicholaswilliams.net%3E
> 
> hints that this is fully possible. This is also a very nice feature for
> webapps (especially those running in a cluster) because editing a file on
> the server is error prone and sometimes not even possible.
> 
> The docs for log4j2 is pretty great overall but I would really like some
> info on setting the levels programmatically...
> 
> Thanks for log4j, a staple framework I use for every project :-) Time to
> upgrade to log4j2 (hence the question)
> 
> cheers