commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <fzli...@omnytex.com>
Subject Re: [JCL] Logging for specific classes
Date Sat, 22 Apr 2006 04:23:01 GMT
Simon Kitching wrote:
> On Sat, 2006-04-22 at 00:00 -0400, Frank W. Zammetti wrote:
>> Ah, ok, so then a logger is named after the package of the class it is 
>> defined in?  If xxxx is the name of the logger, as the docs say, that 
>> would make sense (and that would also be the missing piece of the puzzle 
>> I needed to understand that, because I had read those docs before).
> 
> No, a logger can be named anything at all.
> 
> As a convenience, a Class can be passed in which case the name =
> class.getName(). Log objects don't have to have names which match the
> class they are used by, but it's a very common convention.

I didn't realize that, I thought it was a requirement.

> In 99% of cases, when loggers are created they are created by passing a
> Class object, ie have name of the class that created them.
> 
> package example.foo;
> public Widget {
>   // log has name(aka category) of example.foo.Widget
>   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 :)

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 com.company.app.ClassA, 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:

-Dorg.apache.commons.logging.simplelog.log.com.company.app=debug

Will it actually do anything?  I mean, won't it be looking for a logger 
with the name "com.company.app", when in fact there is none because it's 
either "com.company.app.ClassA" 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 "com.company.app" 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!)

Thanks again Simon!

> Regards,
> 
> Simon

Frank

> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Java Web Parts -
http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message