commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: [JCL] Logging for specific classes
Date Sat, 22 Apr 2006 05:35:25 GMT
On Sat, 2006-04-22 at 00:23 -0400, Frank W. Zammetti wrote:
> > 
> > package;
> > public Widget {
> >   // log has name(aka category) of
> >   private Log log = LogFactory.getLog(Widget.class);
> > 
> >   // special log object for issuing messages that can be
> >   // filtered/written using rules different from the ones
> >   // for class-specific log messages.
> >   private Log sysAdminLog = LogFactory.getLog("sysadmin-alerts");
> > }
> Yep, exactly what I've always done.  Didn't realize I had a choice :)

Did you notice that the example created *two* loggers, one following the
normal name=classname convention, and one that doesn't?

> I guess now I'm not quite understanding what the xxxx is then in the 
> config... would I then have to use the same name in all the classes of a 
> given package?
> In other words, like I said, I usually use the Class name paradigm as 
> you describe... so, let's say I have a class, the 
> logger would be named "ClassA" (or would it be the fully-qualified name? 
>   I'd still have the same question either way)... So, if in the config I 
> specify:
> Will it actually do anything?  I mean, won't it be looking for a logger 
> with the name "", when in fact there is none because it's 
> either "" or simply "ClassA"? (not sure off-hand 
> what you get from the .class property, fully-qualified name or not).
> But, if I used the same logger name, say "" for all the 
> classes in that package (can I even do that?), then it makes sense to me 
> how it would work.  But outside that, I guess I'm still not clear (I'm 
> probably just being thick-headed in any case!)

When you configure logging for category "", that
configuration applies to a category with that name, or any name that
*starts* with that prefix, unless there is a more specific config.


log0 = LogFactory.getLog("sysadmin-alerts");
log1 = LogFactory.getLog("org.apache.Foo");
log2 = LogFactory.getLog("");
log3 = LogFactory.getLog("");

messages logged via log0 or log1:
     --> no special config, so default applies.
     --> only FATAL gets logged

messages logged via log2 
     --> nearest match is ""
     --> DEBUG and greater get logged

messages logged via log3 
     --> nearest match is ""
     --> WARN and greater get logged

SimpleLog works just like log4j or java.util.logging in this regard. See
the documenation for log4j or java.util.logging if you need more info.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message