You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Will Sargent <wi...@gmail.com> on 2007/10/25 23:37:04 UTC

Changing logging levels in Log4J dynamically?

Hi all,

I've heard several people ask if you can change log4j levels
dynamically, once the application is already running. I see that
there's a JMX package in 1.2.14, but there doesn't seem to be any
javadoc or documentation attached to it.  If there is, can someone
point me to it?

Will.

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


Re: Changing logging levels in Log4J dynamically?

Posted by Jess Holle <je...@ptc.com>.
Will Sargent wrote:
> I've researched this in the past, and I did find a number of examples
> of people using JMX with log4j.  So it's doable.
>
> http://blogs.averconsulting.com/2006/12/13/changing-log4j-logging-levels-dynamically.aspx
>
> http://www.devx.com/Java/Article/32359/1954?pf=true
>
> http://technology.amis.nl/blog/?p=1238
>
> If the JMX code in 1.2.14 is not usable on its own, what does it do?
> Is it a starting point?
>   
The JMX code in 1.2.x was usable for /some/ things for /some/ usage 
scenarios when I tried it.  It had some bugs that may have since been 
fixed, but the lack of support for multiple LoggerRepository's was 
systemic at that time.

Even if you need multiple LoggerRepository support (which not everyone 
does), the existing JMX code is a good starting point at least at the 
code snippet level if not at the class level.

I'm quite happy with my own JMX MBeans for log4j.  I looked at how the 
built-in log4j MBeans did things, but went my own way in a good number 
of cases and added support for multiple LoggerRepository's.  I'd share 
my MBeans, but my employer wouldn't like that -- and they use other 
pieces of our JMX framework anyway.

--
Jess Holle


Re: Changing logging levels in Log4J dynamically?

Posted by Will Sargent <wi...@gmail.com>.
I've researched this in the past, and I did find a number of examples
of people using JMX with log4j.  So it's doable.

http://blogs.averconsulting.com/2006/12/13/changing-log4j-logging-levels-dynamically.aspx

http://www.devx.com/Java/Article/32359/1954?pf=true

http://technology.amis.nl/blog/?p=1238

If the JMX code in 1.2.14 is not usable on its own, what does it do?
Is it a starting point?

Will.

On 10/25/07, Jess Holle <je...@ptc.com> wrote:
> Though I believe there have been recent fixes to it, I ended up giving
> up on the JMX package in log4j and writing my own.
>
> You may be able to make it work well enough for your cases if you only
> have a single LoggerRepository, though.  If not, well last I saw it had
> no notion or ability to cope with multiple repositories and I'd suggest
> using the code as an sample code for writing your own at that point --
> taking what you like and leaving the rest :-)
>
> As for documentation, I'd suggest running with Java 5, adding the bit of
> code to register the MBeans, connecting to your running app with
> jconsole and playing around.  You'll quickly see what's handled to your
> liking and what's not this way.
>
> Besides JMX, there's always just calling setLevel() yourself -- as
> triggered by an HTTP request, for example.  You can also watch for
> modifications to the log4j configuration file and reconfigure when it
> changes -- not instantaneous, but still no restart required.
>
> --
> Jess Holle
>
> Will Sargent wrote:
> > Hi all,
> >
> > I've heard several people ask if you can change log4j levels
> > dynamically, once the application is already running. I see that
> > there's a JMX package in 1.2.14, but there doesn't seem to be any
> > javadoc or documentation attached to it.  If there is, can someone
> > point me to it?
> >
> > Will.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-dev-help@logging.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>

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


Re: Changing logging levels in Log4J dynamically?

Posted by Jess Holle <je...@ptc.com>.
Though I believe there have been recent fixes to it, I ended up giving 
up on the JMX package in log4j and writing my own.

You may be able to make it work well enough for your cases if you only 
have a single LoggerRepository, though.  If not, well last I saw it had 
no notion or ability to cope with multiple repositories and I'd suggest 
using the code as an sample code for writing your own at that point -- 
taking what you like and leaving the rest :-)

As for documentation, I'd suggest running with Java 5, adding the bit of 
code to register the MBeans, connecting to your running app with 
jconsole and playing around.  You'll quickly see what's handled to your 
liking and what's not this way.

Besides JMX, there's always just calling setLevel() yourself -- as 
triggered by an HTTP request, for example.  You can also watch for 
modifications to the log4j configuration file and reconfigure when it 
changes -- not instantaneous, but still no restart required.

--
Jess Holle

Will Sargent wrote:
> Hi all,
>
> I've heard several people ask if you can change log4j levels
> dynamically, once the application is already running. I see that
> there's a JMX package in 1.2.14, but there doesn't seem to be any
> javadoc or documentation attached to it.  If there is, can someone
> point me to it?
>
> Will.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>
>   


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


Re: Changing logging levels in Log4J dynamically?

Posted by Curt Arnold <ca...@apache.org>.
As far as I recall, the current JMX code was added in one commit long  
time ago by a single developer with no preceding discussion about use  
cases, design strategies, etc, little or no feedback after it was  
introduced and no unit tests.  Since it has been present in log4j  
releases, the project can't make any changes that would break  
compatibility.

Pretty much means that any serious work on JMX would need to be done  
in an sandbox project using different package names, etc.  Obviously,  
this time we would want discussion, unit tests and the like.  One of  
my goals for log4j 2.0 development was to rethink the whole  
configuration space and making it much more friendly to JMX or JMX- 
centric.  So if a JMX sandbox project starts up, the first thing to  
look at is whether it wasn't to design for log4j 2.0 and then  
possibly retrofit for log4j 1.2 or design for log4j 1.2.  There has  
been some previous discussion, so anyone interested could search at  
the archives and the bug list for JMX.


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


Re: Changing logging levels in Log4J dynamically?

Posted by Jess Holle <je...@ptc.com>.
Jacob Kjome wrote:
> Will Sargent wrote:
>> Jacob Kjome wrote:
>>> I'm not so familiar with the JMX stuff, but if you are using this in 
>>> an application server, you can use something like LogWeb...
>>>
>>> http://www.codeczar.com/projects/components/logweb/index.html
>>>
>>> BTW, this really is a log4j-user list question, not a log4j-dev list 
>>> mail.  Please use the proper list.  You'll probably get more 
>>> response there anyway.
>> I'd argue that this is a log4j-dev question.  The question is not 
>> "How do you do this?"  I know there are multiple ways in which this 
>> can be done, and I've even listed a few myself.
>>
>> The question I'm asking more along the lines of "Is there any ability 
>> (or declared intent) for doing this as part of the log4j core 
>> library, without writing too much code?"
> I think there's opportunities for that in the extras modules.  I think 
> the core will more or less be maintained and bug fixed... and later 
> rewritten, if anyone actually finds the time to do it.  But the 
> extras, which are a more recent phenomenon are more amenable to 
> additions.  I'm not sure how much thought the other developers have 
> given to this.  I don't have the time.  But I think it's a great 
> opportunity for someone to contribute something that could actually be 
> released as an official log4j package, albeit not the core.
It's not worth the compatibility break, but otherwise I'd argue the JMX 
stuff (however brilliantly it is or is not working) should be in extras, 
not the core library anyway.

Certainly a "skinny" version of the log4j jar without this and various 
bits one wouldn't usually want to do from a client enough to pay for 
them in the download (e.g. e-mail and JDBC logging) would be a nice 
thing to have.  Obviously anyone can make one, it would be nice to have 
one in the distribution.

--
Jess Holle


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


Re: Changing logging levels in Log4J dynamically?

Posted by Jacob Kjome <ho...@visi.com>.
Will Sargent wrote:
> Jacob Kjome wrote:
>> I'm not so familiar with the JMX stuff, but if you are using this in 
>> an application server, you can use something like LogWeb...
>>
>> http://www.codeczar.com/projects/components/logweb/index.html
>>
>> BTW, this really is a log4j-user list question, not a log4j-dev list 
>> mail.  Please use the proper list.  You'll probably get more response 
>> there anyway.
> I'd argue that this is a log4j-dev question.  The question is not "How 
> do you do this?"  I know there are multiple ways in which this can be 
> done, and I've even listed a few myself.
> 
> The question I'm asking more along the lines of "Is there any ability 
> (or declared intent) for doing this as part of the log4j core library, 
> without writing too much code?"
> 

I think there's opportunities for that in the extras modules.  I think 
the core will more or less be maintained and bug fixed... and later 
rewritten, if anyone actually finds the time to do it.  But the extras, 
which are a more recent phenomenon are more amenable to additions.  I'm 
not sure how much thought the other developers have given to this.  I 
don't have the time.  But I think it's a great opportunity for someone 
to contribute something that could actually be released as an official 
log4j package, albeit not the core.

Jake

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

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


Re: Changing logging levels in Log4J dynamically?

Posted by Will Sargent <wi...@gmail.com>.
Jacob Kjome wrote:
> I'm not so familiar with the JMX stuff, but if you are using this in 
> an application server, you can use something like LogWeb...
>
> http://www.codeczar.com/projects/components/logweb/index.html
>
> BTW, this really is a log4j-user list question, not a log4j-dev list 
> mail.  Please use the proper list.  You'll probably get more response 
> there anyway.
I'd argue that this is a log4j-dev question.  The question is not "How 
do you do this?"  I know there are multiple ways in which this can be 
done, and I've even listed a few myself.

The question I'm asking more along the lines of "Is there any ability 
(or declared intent) for doing this as part of the log4j core library, 
without writing too much code?"

Will.


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


Re: Changing logging levels in Log4J dynamically?

Posted by Jacob Kjome <ho...@visi.com>.
I'm not so familiar with the JMX stuff, but if you are using this in an 
application server, you can use something like LogWeb...

http://www.codeczar.com/projects/components/logweb/index.html

BTW, this really is a log4j-user list question, not a log4j-dev list 
mail.  Please use the proper list.  You'll probably get more response 
there anyway.


Jake

Will Sargent wrote:
> Hi all,
> 
> I've heard several people ask if you can change log4j levels
> dynamically, once the application is already running. I see that
> there's a JMX package in 1.2.14, but there doesn't seem to be any
> javadoc or documentation attached to it.  If there is, can someone
> point me to it?
> 
> Will.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 
> 
> 
> 

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