Just wondering what approach you guys took with logging to determine where
you should put logging statements?
Three rules so far that I have:
1) Log entry and exit to every method (Andrew Monkhouse gives an example of using this in his book). Include argument information selectively (see point 3).
2) If an exception is caught, then I log the exception.
3) Log method arguments that have a large amount of data at the level of FINEST and don't include the argument information in the entering\exiting log method calls.
I am going to use (1) with classes in my
suncerify.db package. So for example my Data class and my DataManager class (my class that deals with file I/O). I think (1) would be an overkill in other classes.
I am going to use (2) everywhere I catch an exception. Because I think in general it's good practice to log an exception that you catch. But I'm not sure if it's a good idea to log the exception if am I going to rethrow it, what you guys think?
I was thinking about logging some information before I throw an exception. But not sure about this approach. Probably best to just log the exception when catching it. Unless there's some important information not available when the exception is caught, then I should log when throwing? What you guys think on this one?
I read a nice little discussion on this on stackoverflow
see here.