You have two root loggers.  Only one of them is going to take effect. The other 
should have generated an error but it sounds like it didn't. That is a bug and 
needs to be fixed.

It sounds like the second root logger is "winning" and so all messages except 
those marked as trace will go to the console. I'm not sure the wording is 
correct but there is a table at 
http://logging.apache.org/log4j/2.x/manual/architecture.html that discusses the 
log levels.  Basically, you have configured the root logger with a level of 
"DEBUG". If you look at the column with the heading of "DEBUG" all the levels 
(on the left) marked as "YES" will appear in the output.  Note that for DEBUG 
the only one with "NO" is TRACE.

The easiest way to do this is to configure loggers for each servlet and then 
specify the logging level you want for each.  So if you have com.acme.ServletA 
and com.acme.ServletB you could do:

<loggers>
  <logger name="com.acme.ServletA" level="TRACE"/>
  <logger name="com.acme.ServletB" level="DEBUG"/>
  <root level="error">
    <appender-ref ref="Console"/>
  <.root>
</loggers>

Ralph



On Mar 13, 2013, at 12:56 PM, Confused Log4J2 User wrote:

> Hi, I have several questions for the group. I have read and studied the 2.x 
> manual, but I could not find any examples or situations related to what I am 
> trying to do.
> 
> 1) My ultimate goal is to have certain levels, like TRACE and DEBUG, to go 
> into 
> the Console. At the same time, I want all of my Error lines to go to a file. 
> When I run this servlet, all ERROR, DEBUG, and INFO lines go automatically to 
> the Console while TRACE is ignored. Nothing ends up in the app.log file. INFO 
> is 
> not in this config file, but why would it appear on my Console?
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration status="warn" name="MyApp" packages="">
>  <appenders>
>    <File name="MyFile" fileName="c:\tmp\app.log">
>      <PatternLayout>
>        <pattern>%d %p %C{1.} [%t] %m%n</pattern>
>      </PatternLayout>
>    </File>
>    <Console name="Console" target="SYSTEM_OUT">
>      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - 
> %msg%n"/>
>    </Console>
>  </appenders>
>  <loggers>
>    <root level="error">
>      <appender-ref ref="MyFile"/>
>    </root>
>    <root level="debug">
>     <appender-ref ref="Console"/>     
>    </root>
>  </loggers>
> </configuration>
> 
> 2) My project will ultimately spawn several servlets, and I'd like an easy 
> way 
> to say "Everything TRACE and below for servlet A" and "DEBUG only for servlet 
> B". How should I go about configuring that?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 

Reply via email to