logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin Jaton <benjamin.ja...@gmail.com>
Subject Log4j2 set log level, cascade
Date Tue, 20 Oct 2015 22:13:36 GMT
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

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