You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Trenton D. Adams" <tr...@athabascau.ca> on 2005/03/24 21:42:04 UTC
commons logging class level logging
I thought I read somewhere that JCL allows one to turn on/off debug
logging based on the package or class name. Is that right? I'm looking
on the JCL website, but can't find information on that. Perhaps that's
because I don't know what to search for!
--
Trenton D. Adams
Web Programmer Analyst
Navy Penguins at your service!
Athabasca University
(780) 675-6195
:wq!
__
This communication is intended for the use of the recipient to whom it
is addressed, and may contain confidential, personal, and or privileged
information. Please contact us immediately if you are not the intended
recipient of this communication, and do not copy, distribute, or take
action relying on it. Any communications received in error, or
subsequent reply, should be deleted or destroyed.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: commons logging class level logging
Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Thu, 2005-03-24 at 13:42 -0700, Trenton D. Adams wrote:
> I thought I read somewhere that JCL allows one to turn on/off debug
> logging based on the package or class name. Is that right? I'm looking
> on the JCL website, but can't find information on that. Perhaps that's
> because I don't know what to search for!
JCL does not control any external logging systems. so, if you are using
JCL to bridge to java.util.logging or Log4J, you need to consult the
appropriate documentation.
(if you are not sure which logging system you're logging to, if you have
not explicitly configured JCL then it will be logging to Log4J if
there's a jar on the classpath, otherwise java.util.logging if you're
running java 1.4 or higher and SimpleLog if lower)
if JCl is logging to it's own minimal, fallback logging system
(SimpleLog) then debugging can be turned on and off. consult the java
documentation for that class and the user guide to learn more details.
- robert
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: commons logging class level logging
Posted by Craig McClanahan <cr...@gmail.com>.
On Thu, 24 Mar 2005 13:42:04 -0700, Trenton D. Adams
<tr...@athabascau.ca> wrote:
> I thought I read somewhere that JCL allows one to turn on/off debug
> logging based on the package or class name. Is that right? I'm looking
> on the JCL website, but can't find information on that. Perhaps that's
> because I don't know what to search for!
Well, that's probably because configuring the underlying logging
system is something external to JCL (i.e. look at the configuration
docs for JDK logging or Log4J logging, or whatever).
That being said, there is a lot of code in the world (including a very
large amount of the Java code at Apache that does logging) which
follows a convention to name your "log" implementation for a
particular class after the fully qualified classname of that
implementation class. Further, it is a common convention for logging
systems (in particular, JDK logging and Log4J do this) to support
"hierarchical" configuration that allows you to specify a general
configuration for a package, but detailed exceptions for lower level
names.
Consider Struts, which follows the naming convention. All classes in
Struts are in package org.apache.struts (or a subpackage like
org.apache.struts.action). Now, assume you're using JDK logging (so
you edit $JAVA_HOME/jre/lib/logging.properties to configure it). I
can have the following lines:
# Set the general logging level for Struts code to INFO
org.apache.struts.level = INFO
# But I want debug level messages from RequestProcessor
org.apache.struts.action.RequestProcessor.level = FINE
# And trace level messages from ModuleUtils
org.apache.struts.action.util.ModuleUtils
You can do the same sort of thing with Log4J by following its
configuration rules.
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: commons logging class level logging
Posted by Simon Kitching <sk...@apache.org>.
Trenton D. Adams wrote:
> What's the quickest and easiest way of my code knowing what class called
> a method? The reason I ask is because we have some wrapper methods in
> our main class that every other class calls to do logging. I would like
> that method to be able to determine what class it was that called, so
> that I could use the proper logger/category.
I don´t believe it is possible, except by requiring the calling method
to pass the associated information as a parameter.
Java 1.5 does provide an API to get a stack trace. Earlier versions of
java provides Throwable.printStackTrace method that can be parsed to
extract the calling method [WARNING: stack trace format can vary by
platform and JVM vendor!]. However there is no guarantee that this
information is actually available at runtime; optimising JVMs can do all
sorts of things that mean that stacktrace information is incomplete or
simply not available; inlining method calls is just one case.
You will see that log4j appenders have %C and %M (I think that´s the
right chars) to insert class and method info into log messages. But I
know from experience that they don´t always work.
If you don´t want to require the source code to explicitly include the
caller information as a parameter, then maybe you can use an
"aspect-oriented" tool (eg aspectJ) to automatically insert the
necessary parameter.
>
> Also, for log4j, is Logger.getLogger("classname") an efficient way of
> getting a logger for each class? e.g. should I be calling this method
> every time my *wrapper* log method is called? How does the commons
> logging do this properly, surely it has to do something similar since
> it's a wrapper too?
commons-logging keeps a hashmap of all the Log objects, keyed by the
category name. Calling getLogger("foo") just does a hashmap lookup to
find and return the appropriate Log object.
And I´m pretty sure log4j internally does the same thing; it just has a
hashmap of all the Logger objects that already exist.
Cheers,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: commons logging class level logging
Posted by Mario Ivankovits <ma...@ops.co.at>.
Hello!
Use a "private final static Log" member in your classes. That way the
logging object is created at startup and thus you no longer have to
spend time for it.
> What's the quickest and easiest way of my code knowing what class
> called a method?
If you use log4j you could configure the pattern of the appender to
provide this information. I dont know now whats the pattern token is,
but you should find it on the log4j homepage.
---
Mario
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: commons logging class level logging
Posted by "Trenton D. Adams" <tr...@athabascau.ca>.
Ok, this is slightly off topic for this list then. But I'd appreciate
any help.
What's the quickest and easiest way of my code knowing what class called
a method? The reason I ask is because we have some wrapper methods in
our main class that every other class calls to do logging. I would like
that method to be able to determine what class it was that called, so
that I could use the proper logger/category.
Also, for log4j, is Logger.getLogger("classname") an efficient way of
getting a logger for each class? e.g. should I be calling this method
every time my *wrapper* log method is called? How does the commons
logging do this properly, surely it has to do something similar since
it's a wrapper too?
Simon Kitching wrote:
> Trenton D. Adams <trenta <at> athabascau.ca> writes:
>
>
>>I thought I read somewhere that JCL allows one to turn on/off debug
>>logging based on the package or class name. Is that right? I'm looking
>>on the JCL website, but can't find information on that. Perhaps that's
>>because I don't know what to search for!
>>
>
>
> JCL is simply a "wrapper" that provides a common API to a number of different
> logging libraries. Configuration of the underlying library is explicitly *not*
> part of JCL.
>
> So if you are using log4j as the underlying library then you need to read up on
> how to configure log4j to turn on/off logging by category name. If you are
> using native jdk-1.4 logging as the underlying logging library then you need to
> read up on configuring that, etc.
>
> Both of the above logging systems *do* have the ability to filter log messages
> based on log category name (and the recommended convention is for code to use
> the current class name as the log category).
>
> Regards,
>
> Simon
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
--
Trenton D. Adams
Web Programmer Analyst
Navy Penguins at your service!
Athabasca University
(780) 675-6195
:wq!
__
This communication is intended for the use of the recipient to whom it
is addressed, and may contain confidential, personal, and or privileged
information. Please contact us immediately if you are not the intended
recipient of this communication, and do not copy, distribute, or take
action relying on it. Any communications received in error, or
subsequent reply, should be deleted or destroyed.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: commons logging class level logging
Posted by Simon Kitching <s_...@yahoo.com>.
Trenton D. Adams <trenta <at> athabascau.ca> writes:
>
> I thought I read somewhere that JCL allows one to turn on/off debug
> logging based on the package or class name. Is that right? I'm looking
> on the JCL website, but can't find information on that. Perhaps that's
> because I don't know what to search for!
>
JCL is simply a "wrapper" that provides a common API to a number of different
logging libraries. Configuration of the underlying library is explicitly *not*
part of JCL.
So if you are using log4j as the underlying library then you need to read up on
how to configure log4j to turn on/off logging by category name. If you are
using native jdk-1.4 logging as the underlying logging library then you need to
read up on configuring that, etc.
Both of the above logging systems *do* have the ability to filter log messages
based on log category name (and the recommended convention is for code to use
the current class name as the log category).
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org