You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Frank W. Zammetti" <fz...@omnytex.com> on 2006/04/21 21:22:35 UTC

[JCL] Logging for specific classes

Hi all,

I seem to remember there being a way to configure JCL, when using
SimpleLog, to only log certain packages, but I forgot how, and Google is
failing me.  I want to log messages only from those classes in my
application code, not those coming from Struts for instance.  Point me in
the right direction?  Thanks!

Frank

-- 
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


Populating a bean with data in a SMALLINT field (Commons-DbUtils)

Posted by Pekka Henttonen <pe...@iki.fi>.
I have a problem with Commons-DbUtils. A query returns three types of
fields from a DB2 database: VARCHAR, CHARACTER and SMALLINT. The first
two populate a JavaBean allright, but SMALLINT data (in a field
called YEAR) never gets into the bean. It seems that the setter method is
not called.

Probably the solution is something simple, but being a newcomer I can't
figure out what it is. Could somebody help and say what to do or check?

So far I have tried changing the parameter types in the bean:

setYear( int year ) {...
setYear( short year ) {...
setYear( String year ) {...

without any success.

With best regards

Pekka






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


Re: [JCL] Logging for specific classes

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Simon Kitching wrote:
> On Sat, 2006-04-22 at 00:23 -0400, Frank W. Zammetti wrote:
>>> 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 :)
> 
> Did you notice that the example created *two* loggers, one following the
> normal name=classname convention, and one that doesn't?

Yep, I did... that was actually the genesis of my further question :)

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

Gotcha, that's the part I was missing, that it's not necessarily looking 
for an *exact* match, a more general one will do unless a more specific 
one is found.

> defaultLog=FATAL
> com.company.app=DEBUG
> com.company.app.unimportant=WARN
> 
> log0 = LogFactory.getLog("sysadmin-alerts");
> log1 = LogFactory.getLog("org.apache.Foo");
> log2 = LogFactory.getLog("com.company.app.widgets.FooWidget");
> log3 = LogFactory.getLog("com.company.app.unimportant.stuff.BarWidget");
> 
> messages logged via log0 or log1:
>      --> no special config, so default applies.
>      --> only FATAL gets logged
> 
> messages logged via log2 
>      --> nearest match is "com.company.app"
>      --> DEBUG and greater get logged
> 
> messages logged via log3 
>      --> nearest match is "com.company.app.unimportant"
>      --> WARN and greater get logged

Excellent explanation, thank you!

> 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.

Ironically, I've only ever dealt with Log4J, and only with XML 
configuration, and I guess some of the concepts expressed as properties 
weren't jiving.

In any case, I very much appreciate your explanation Simon, I believe 
I'm all set now.

> Regards,
> 
> Simon

Frank

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


Re: [JCL] Logging for specific classes

Posted by Simon Kitching <sk...@apache.org>.
On Sat, 2006-04-22 at 00:23 -0400, Frank W. Zammetti wrote:
> > 
> > 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 :)

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 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!)

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

defaultLog=FATAL
com.company.app=DEBUG
com.company.app.unimportant=WARN

log0 = LogFactory.getLog("sysadmin-alerts");
log1 = LogFactory.getLog("org.apache.Foo");
log2 = LogFactory.getLog("com.company.app.widgets.FooWidget");
log3 = LogFactory.getLog("com.company.app.unimportant.stuff.BarWidget");

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

messages logged via log2 
     --> nearest match is "com.company.app"
     --> DEBUG and greater get logged

messages logged via log3 
     --> nearest match is "com.company.app.unimportant"
     --> 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.

Regards,

Simon


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


Re: [JCL] Logging for specific classes

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
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


Re: [JCL] Logging for specific classes

Posted by Simon Kitching <sk...@apache.org>.
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.

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");
}

Regards,

Simon


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


Re: [JCL] Logging for specific classes

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
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).

In any case, thanks Simon!

Frank

Simon Kitching wrote:
> On Fri, 2006-04-21 at 15:22 -0400, Frank W. Zammetti wrote:
>> Hi all,
>>
>> I seem to remember there being a way to configure JCL, when using
>> SimpleLog, to only log certain packages, but I forgot how, and Google is
>> failing me.  I want to log messages only from those classes in my
>> application code, not those coming from Struts for instance.  Point me in
>> the right direction?  Thanks!
>>
> 
> http://jakarta.apache.org/commons/logging/commons-logging-1.0.4/docs/apidocs/org/apache/commons/logging/impl/SimpleLog.html
> 
> java \
>   -Dorg.apache.commons.logging.simplelog.defaultlog=fatal \
>   -Dorg.apache.commons.logging.simplelog.log.example.foo=debug \
>   ....
> 
> will suppress everything except FATAL messages by default, but then
> allow DEBUG messages from classes in package example.foo and its
> subpackages.
> 
> As described in the javadoc, you can also put these settings in a
> "simplelog.properties" file in the classpath (I haven't tried this
> myself).
> 
> Regards,
> 
> Simon
> 
> 
> ---------------------------------------------------------------------
> 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


Re: [JCL] Logging for specific classes

Posted by Simon Kitching <sk...@apache.org>.
On Fri, 2006-04-21 at 15:22 -0400, Frank W. Zammetti wrote:
> Hi all,
> 
> I seem to remember there being a way to configure JCL, when using
> SimpleLog, to only log certain packages, but I forgot how, and Google is
> failing me.  I want to log messages only from those classes in my
> application code, not those coming from Struts for instance.  Point me in
> the right direction?  Thanks!
> 

http://jakarta.apache.org/commons/logging/commons-logging-1.0.4/docs/apidocs/org/apache/commons/logging/impl/SimpleLog.html

java \
  -Dorg.apache.commons.logging.simplelog.defaultlog=fatal \
  -Dorg.apache.commons.logging.simplelog.log.example.foo=debug \
  ....

will suppress everything except FATAL messages by default, but then
allow DEBUG messages from classes in package example.foo and its
subpackages.

As described in the javadoc, you can also put these settings in a
"simplelog.properties" file in the classpath (I haven't tried this
myself).

Regards,

Simon


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