Re: Log4j2: Programmatically setting log4j2 log level

2013-08-14 Thread Gary Gregory
On Wed, Jul 24, 2013 at 12:22 PM, Gary Gregory garydgreg...@gmail.comwrote: On Mon, Jul 22, 2013 at 5:59 PM, Ralph Goers ralph.go...@dslextreme.comwrote: Well, you can actually do that. It is just not my number one recommendation :-) I'm pretty sure I have answered how to do that a few

Re: Log4j2: Programmatically setting log4j2 log level

2013-08-14 Thread Ralph Goers
I will have to create an example. Ralph On Aug 14, 2013, at 8:27 AM, Gary Gregory wrote: On Wed, Jul 24, 2013 at 12:22 PM, Gary Gregory garydgreg...@gmail.comwrote: On Mon, Jul 22, 2013 at 5:59 PM, Ralph Goers ralph.go...@dslextreme.comwrote: Well, you can actually do that. It is just

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-24 Thread Gary Gregory
On Mon, Jul 22, 2013 at 5:59 PM, Ralph Goers ralph.go...@dslextreme.comwrote: Well, you can actually do that. It is just not my number one recommendation :-) I'm pretty sure I have answered how to do that a few times. It just needs to be documented. The actual code to do this is

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-24 Thread Gary Gregory
On Mon, Jul 22, 2013 at 5:59 PM, Ralph Goers ralph.go...@dslextreme.comwrote: Well, you can actually do that. It is just not my number one recommendation :-) I'm pretty sure I have answered how to do that a few times. It just needs to be documented. The actual code to do this is

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-23 Thread Ralph Goers
I should add that the LoggerConfig and Configuration was one of the first things I worked on when I started working on 2.0. Things have changed since then so it might possible to add a new LoggerConfig to an existing configuration. I'd have to review it and remind myself of what the problems

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-23 Thread Gary Gregory
And if you can Javadoc things as you recall them, that much the better! :) Gary On Jul 23, 2013, at 11:23, Ralph Goers ralph.go...@dslextreme.com wrote: I should add that the LoggerConfig and Configuration was one of the first things I worked on when I started working on 2.0. Things have

Log4j2: Programmatically setting log4j2 log level

2013-07-22 Thread SMITH, CURTIS
From a thread back in May: My question to the below snips of the thread are; My app has many Catagories (using 1.x terminology). To setLevel in 1.x I had to getCurrentCatagories() and iterate over the list setting level. In 2.x, does the code below set all Appenders regardless of what Level

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-22 Thread Ralph Goers
Can you explain what it is you are really trying to do? Rather than just answer specific questions I am wondering if there isn't a better way to do what you want. Ralph On Jul 22, 2013, at 7:14 AM, SMITH, CURTIS wrote: From a thread back in May: My question to the below snips of the

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-22 Thread Gary Gregory
Here is a user story I have at work all the time, which I'd like to be able to do in Log4J 2 when we eventually migrate to it. Our server starts. A couple of days later, something goes wrong. Our user contacts us and we tell them to use our admin console to enable debugging for X and Y. This

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-22 Thread Nick Williams
We do the _exact same thing_ in our apps that use Log4j 1. Being able to do this is crucial to us. Being able to do this using the API is ideal and obviously preferred so that the Core can be a runtime dependency, but as long as we can do it one way or another we're ok. Nick On Jul 22, 2013,

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-22 Thread Gary Gregory
This seems like an obvious feature and should be part of the public API/feature set (IMO). Gary On Mon, Jul 22, 2013 at 3:08 PM, Nick Williams nicho...@nicholaswilliams.net wrote: We do the _exact same thing_ in our apps that use Log4j 1. Being able to do this is crucial to us. Being able

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-22 Thread Ralph Goers
The way I recommend would be to clone the active Configuration, make the desired modifications to it and then replace the Configuration. That will take care of updating all the loggers and won't have threading issues. I noticed that the JMX stuff doesn't do that. Ralph On Jul 22, 2013, at

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-22 Thread Ralph Goers
I guess I have to disagree. With Logback it is more explicit since SLF4J is its API. The more of this stuff that gets added to the API the more difficult it is going to be to keep the API separate from the implementation. My view is that the API is primarily for applications that want to use

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-22 Thread Nicholas Williams
I can live with having to use the Core directly to change logger levels, as opposed to using the API. But your solution of cloning, changing, and replacing the configuration seems extremely heavy and excessive for merely changing the level for a single logger. There are a lot of other things that

Re: Log4j2: Programmatically setting log4j2 log level

2013-07-22 Thread Ralph Goers
Well, you can actually do that. It is just not my number one recommendation :-) I'm pretty sure I have answered how to do that a few times. It just needs to be documented. The actual code to do this is LoggerContext ctx = (LoggerContext) LogManager.getContext(false);

Re: Programmatically setting log4j2 log level

2013-05-19 Thread Ralph Goers
Yes, that is correct. The getRootLogger method is not included in the Configuration interface. I created a unit test to verify the code worked and I should have pasted the code from the test. Ralph On May 18, 2013, at 7:26 PM, Eric Scheie wrote: I should add that I didn't find the

Re: Programmatically setting log4j2 log level

2013-05-18 Thread Eric Scheie
Thanks Ralph! That was the code snippet I was looking for. Works great! Best, -Eric On Fri, May 17, 2013 at 10:39 PM, Ralph Goers ralph.go...@dslextreme.comwrote: No, the X Logger does not inherit its level from the root Logger. It inherits its level from the root LoggerConfig. See the

Re: Programmatically setting log4j2 log level

2013-05-18 Thread Scott Deboy
From looking at this, seems like config.getRootLoggerConfig() would be a better name. On May 17, 2013 10:40 PM, Ralph Goers ralph.go...@dslextreme.com wrote: No, the X Logger does not inherit its level from the root Logger. It inherits its level from the root LoggerConfig. See the picture at

Re: Programmatically setting log4j2 log level

2013-05-18 Thread Nick Williams
I agree, Scott. On May 18, 2013, at 11:11 AM, Scott Deboy wrote: From looking at this, seems like config.getRootLoggerConfig() would be a better name. On May 17, 2013 10:40 PM, Ralph Goers ralph.go...@dslextreme.com wrote: No, the X Logger does not inherit its level from the root Logger.

Re: Programmatically setting log4j2 log level

2013-05-18 Thread Eric Scheie
I should add that I didn't find the getRootLogger method in the API. This is the actual code I used. LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.

Re: Programmatically setting log4j2 log level

2013-05-17 Thread Ralph Goers
Can you provide a sample application that demonstrates this? Ralph On May 16, 2013, at 9:44 PM, Eric Scheie wrote: I'm developing a web application and would like to be able to dynamically change log levels from within my application instead of editing the log4j2 configuration file. I'm

Re: Programmatically setting log4j2 log level

2013-05-17 Thread Eric Scheie
Here is a simple program that can reproduce my problem: import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class Main { public static void main(String[] args) { Logger rootLogger =

Re: Programmatically setting log4j2 log level

2013-05-17 Thread Ralph Goers
No, the X Logger does not inherit its level from the root Logger. It inherits its level from the root LoggerConfig. See the picture at http://logging.apache.org/log4j/2.x/manual/architecture.html. The level you are modifying is brought into each Logger so that the level can be tested very

Programmatically setting log4j2 log level

2013-05-16 Thread Eric Scheie
I'm developing a web application and would like to be able to dynamically change log levels from within my application instead of editing the log4j2 configuration file. I'm using log4j 2.0 beta5. I'm currently setting the log level after a form submit using: