Bender,

You are correct in your latest analysis, but incorrect on your original
analysis.  Chuanjiang's original XML file was just fine and the fact that he
increased the level to "error" should have made it so that only ERROR messages
would print to the A1 appender for that specific logger, while all other
loggers would print to the "debug" level.

There are a couple possibilities why this might not be working.

1.  As you mentioned, the logger name might not exactly match that being
referenced in the log4j.xml file

2.  Another config file is being used instead of this one.


Note that the approach I would generally take to configuration is to set the
root logger to some higher level such as "warn" and then selectively set
loggers to debug where I truly want to see debug output.


Jake

Quoting Bender Heri <[EMAIL PROTECTED]>:

> It shouldn't. Maybe you are not fetching the logger correctly. How you
> instantiate the logger in the Main class? It should be:
>
>     Logger.getLogger( "loggingexample.Main" )
>
> or
>
>     Logger.getLogger( this.getClass() )
>
> The latter is only valid if "loggingexample.Main" is exactly the FQCN of MAIN
> (normally there is a a toplevel domain in front, i.e.
> "com.loggingexample.Main").
>
> Try it with annother appender (maybe FileAppender) for the
> "loggingexample.Main"-Logger. So you can see which logger outputs the event.
>
> Heri
>
> > -----Original Message-----
> > From: chuanjiang lo [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, December 05, 2006 12:30 PM
> > To: Log4J Users List
> > Subject: Re: Setting up log4j.xml
> >
> >
> > On 12/5/06, Bender Heri <[EMAIL PROTECTED]> wrote:
> > >
> > > Log events which are sent to a specialized Logger (=not
> > Root Logger) will
> > > by default climb up the logger hierarchy until the root
> > logger and serve
> > > every appender of every logger found on its way. Your
> > example: a log event
> > > sent to logger named "loggingexample.Main" arrieves to this
> > logger, does
> > > not find an appender, looks up the next upper logger in
> > hierarchy, finds the
> > > root logger with level DEBUG and serves its appender A1.
> > >
> > > To achieve what you want, supply the logger
> > "loggingexample.Main" with the
> > > appender-ref A1 and set the logger's property
> > additivity=false. This will
> > > prevent the log event to climb further up the hierarchy.
> > >
> > >     <logger name="loggingexample.Main" additivity="false">
> > >          <level value="error"/>
> > >          <appender-ref ref="A1" />
> > >      </logger>
> > >
> > > Heri
> >
> >
> > This is my current xml configuration..somehow the class Main
> > still prints
> > out those levels that are below error.
> >
> > <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";
> > debug="false">
> >
> >     <appender name="A1" class="org.apache.log4j.ConsoleAppender">
> >         <layout class="org.apache.log4j.PatternLayout">
> >             <!-- Print the date in ISO 8601 format -->
> >             <param name="ConversionPattern" value="%d [%t]
> > %-5p %c - %m%n"/>
> >
> >         </layout>
> >     </appender>
> >
> >     <logger name="loggingexample.Main" additivity="false">
> >         <level value="error"/>
> >         <appender-ref ref="A1"/>
> >     </logger>
> >
> >     <root>
> >         <level value="debug"/>
> >         <appender-ref ref="A1"/>
> >     </root>
> > </log4j:configuration>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to