You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/12/11 00:13:51 UTC

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) {
        log.info(msg);
    }
    //etc
}

"taskmanager" corresponds to a category in my log4j.properties 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
Logging.info("...") 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

-- 

Rick
mailto:maillist@reumann.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Re[2]: Best Practices for Logging?

Posted by Rick Reumann <ma...@reumann.net>.
On Tue, 10 Dec 2002 17:34:10 -0800 (PST)
"Craig R. McClanahan" <cr...@apache.org> wrote:
 
> 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.
> 

Yes, I see your point. I guess I was trying to avoid having to put
something like:

Category log = Category.getInstance( FooThisClass.class.getName() );

on the top of each class (or maybe that doesn't have to be done?). I was
thinking what if later on I decide not to use log4j then all my classes
would still be tied to it would they not? By going straight to another
class called "Logging" I could then implement any other type of logging
I like in the future, but I guess the drawback is the lack of fine
grained logging. Would it be a bad idea to possibly pass the name of the
class you want logging for to another class? That way if I ever decided
to a different type of logging in the future the app would still work
fine. For example if I had an a class called "Logging" I could now call
the Logging methods in this class from another class as such...

Logging.debug("FooBarName.class", "my message to log" );
 
I really should do some more reading on how to better implement log4j in
my Struts apps. Any good pointers to sources for this particular topic?

Thanks for the help.

Rick
 
 
<MY ORIGINAL POST:>

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) {
        log.info(msg);
    }
    //etc
}

"taskmanager" corresponds to a category in my log4j.properties 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
Logging.info("...") 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

-- 
Rick

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Re[2]: Best Practices for Logging?

Posted by Gemes Tibor <ge...@regens.hu>.
2002. december 11. 02:34 dátummal Craig R. McClanahan ezt írtad:
> 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.

This is really important imho. One day I accidentally turned on debug 
globally, and soooo many messages from sooo many places (commons, struts, my 
own app etc) flooded me with DEBUG, that I daresay noone could use that 
output. I am (and suppose you are) interested in DEBUG from the currently 
changed class exclusively, and at most WARN from the others.

Tib

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re[2]: Best Practices for Logging?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 10 Dec 2002, Rick Reumann wrote:

> Date: Tue, 10 Dec 2002 18:13:51 -0500
> From: Rick Reumann <ma...@reumann.net>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
>      Rick Reumann <ma...@reumann.net>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> 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) {
>         log.info(msg);
>     }
>     //etc
> }
>
> "taskmanager" corresponds to a category in my log4j.properties 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
> Logging.info("...") 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
> mailto:maillist@reumann.net
>

Craig



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>