logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: Log4j2 set log level, cascade
Date Tue, 20 Oct 2015 22:26:19 GMT
Check out the
APIs org.apache.logging.log4j.core.config.Configurator.setAllLevels(String,
Level) and setLevel().

Gary

On Tue, Oct 20, 2015 at 3:13 PM, Benjamin Jaton <benjamin.jaton@gmail.com>
wrote:

> Hello,
>
> Here is a simple configuration:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="WARN">
>   <Appenders>
>     <Console name="Console" target="SYSTEM_OUT">
>       <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} -
> %msg%n"/>
>     </Console>
>   </Appenders>
>   <Loggers>
> *    <Logger name="com.foo.Bar" level="trace">*
>       <AppenderRef ref="Console"/>
>     </Logger>
> *    <Logger name="com.foo.Test" level="trace">*
>       <AppenderRef ref="Console"/>
>     </Logger>
> *    <Root level="error">*
>       <AppenderRef ref="Console"/>
>     </Root>
>   </Loggers>
> </Configuration>
>
> I am trying to programmatically set the log level of "com.rli", but I can't
> find the Loggers until they are used:
>
>
>
>
>
>
>
>
>
>
>
>
> *System.setProperty("log4j.configurationFile",
> "/tmp/test.xml");LogManager.getLogger("com.foo.Test");LoggerContext ctx =
> (LoggerContext) LogManager.getContext(false);Configuration conf =
> ctx.getConfiguration();for (Logger l : ctx.getLoggers()) {    LoggerConfig
> config = conf.getLoggerConfig(l.getName());    System.out.println("Found
> logger " + l.getName());}*
> This will only show the com.foo.Test Logger because I created it just
> before, but it will not find com.rli.Bar.
> How can I get ALL the loggers, so that I can then set their log level?
>
> Note that setting directly the log level of "com.rli" will not work because
> what is defined for com.rli.Bar in the conf file will take precedence.
>
> Thanks
> Ben
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message