struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krishnakumar N <>
Subject RE: Best Practices for Logging?
Date Wed, 11 Dec 2002 05:56:18 GMT
I too use a similar method (static methods in a 'Logging' class) to enable
logging from all the classes in the application without having any log4j
initialization code in every class. The loss of flexibility (where you can
control the verbosity of the output per class etc.) has not proven to be too
contraining, atleast till now.

One thing though. You will find that with your current implementation, if
you ever turn on class/method info (%C.%M) in the log output, that the
output will point to the Logging class/method and not the class/method which
invoked the log call. I sorted this out by making the logger class return a
log from a static method. So the client classes' code will look like


With this method, I think you can also eventually make the getLog() return a
class-specific category/logger, if need be, by running up the stacktrace to
determine the caller's class. Bound to make things slower, though... 


-----Original Message-----
From: Craig R. McClanahan []
Sent: Wednesday, December 11, 2002 7:04 AM
To: Struts Users Mailing List; Rick Reumann
Subject: Re[2]: Best Practices for Logging?

On Tue, 10 Dec 2002, Rick Reumann wrote:

> Date: Tue, 10 Dec 2002 18:13:51 -0500
> From: Rick Reumann <>
> Reply-To: Struts Users Mailing List <>,
>      Rick Reumann <>
> To: Struts Users Mailing List <>
> Subject: Re[2]: Best Practices for Logging?
> I apologize, I haven't been following this whole thread, but I'm
> wondering if what I've implemented is a poor solution. For a
> particular app called "taskmanager" I created a Logging class which is
> pretty small and looks like this:
> public class Logging {
>     static Category log = Category.getInstance("taskmanager");
>     public static void debug(String msg) {
>         log.debug(msg);
>     }
>     public static void error(String msg) {
>         log.error(msg);
>     }
>     public static void info(String msg) {
>     }
>     //etc
> }
> "taskmanager" corresponds to a category in my file so
> that I can set up what I want for the app this way. Then wherever I
> need to do logging in the app I just call
>"...") or Logging.error(" ")..etc
> Are there some major drawbacks to using this type of a solution? I'm
> pretty much a log4j newbie so I'm probably missing a better way to do
> all of this and will go back through the archives to read these past
> posts.
> Thanks for any feedback

If I'm understanding what you are doing correctly, doesn't this make the
logging level global to all logging in your application?  The approach
Struts uses internally (essentially a category name per class) lets you
make much more fine grained decisions about wanting DEBUG messages from
this class, but WARN messages from that class.

> --
> Rick


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

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

View raw message