logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francesco Chicchiriccò <ilgro...@apache.org>
Subject Re: Dynamically (programmatically) add logger in Log4j2
Date Mon, 16 Dec 2013 15:10:21 GMT
On 16/12/2013 16:06, dxande6 wrote:
> I'm trying to create an admin console for log4j2 similar to what we have done
> for log4j 1.x
>
> We list out the loggers and their current log level.  We also have links on
> the right side to allow users to click on the link and let them update their
> log level to any level of their choosing.  Finally, we give them a text box
> to add a new logger (i.e., x.y.z), indicate their log level and click add.
>
> Unfortunately, I have not found a way to add a new logger programmatically
> in log4j2.  Does anyone have any advice on how I can do this
> programmatically?  It needs to be dynamic in case the logger was not created
> at the time of deployment.

Hi,
we had similar need and solved as you can see from [1] (among other 
stuff), e.g.

LoggerContext ctx = (LoggerContext) LogManager.getContext(false);

LoggerConfig logConf = ctx.getConfiguration().getLoggerConfig("THE NAME 
OF YOUR NEW LOGGER");
logConf.setLevel(...);

ctx.updateLoggers();

HTH
Regards.

[1] 
https://svn.apache.org/repos/asf/syncope/trunk/core/src/main/java/org/apache/syncope/core/init/LoggerLoader.java

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/


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


Mime
View raw message