Re: Logging Best Practice?




On Thu, 29 Dec 2005, Jeffery wrote:

This might seem like a trivial point, but I'm curious what others are doing regarding logging before an event or after an event, in general. Here is a pseudo-code example:

<code>
some_action_B
if (return_code == good)
   log "Some action B succeeded."
else {
   log "Some action B failed."
   do_failure_logic
}
</code>

This is good feedback for the user (read: admin), in case something goes mildly wrong and he needs to read the log to find out the first stage at
which a problem was detected. "Oops, action B failed! I guess I'd better
go look at B-dot-config..."


<code>
log "Performing action Y."
some_action_Y
</code>

This is the easiest way to debug a broken program. If the programmer sees "Performing action Y..." followed by a crash, he can be pretty sure the error is somewhere in the code for action Y. As you pointed out, trying to print this message /after/ action Y is completed doesn't really help the debugging programmer.

  Programs that aren't broken don't need this kind of logging, I suppose.
On the other hand, it's a courtesy to the guy who'll come after you and
break the program anyway. :)

  Bottom line: What's the purpose of your logging code? Is it to help
the user understand what happened, later on; or is it to help yourself
fix a broken program right now?

-Arthur
.



Relevant Pages

  • Re: Column numbers in stack trace - enhancement request
    ... The logging packages give the programmer explicit control over this behavior and others that you described. ... In the log message you can include any useful information available, which at the point of capture can be pretty darn fine grained. ... The logging mechanism itself will timestamp the entries, provide class and thread context, and do other useful stuff under the hood. ... This does mean writing a whole mess o' catch blocks and if blocks with message string construction and log calls, ...
    (comp.lang.java.programmer)
  • Logging Best Practice?
    ... doing regarding logging before an event or after an event, ... The above two examples are typical of how I usually code logging into ... log "Performing action X." ... about step Y, which is OK for me because I know about my logging style, ...
    (comp.programming)
  • Re: File manipulations in Ada.Text_IO
    ... such a race condition, and their customer trips over it once in a while, the programmer might never find out about it. ... After a year of use, there were no reports of conflicts, so I took the logging out. ...
    (comp.lang.ada)
  • Re: Logging!!?
    ... I used log4j and also familiar with this. ... Was there any discussion on the better way of logging in .NET ?? ... >> Serious Programmer ...
    (microsoft.public.dotnet.languages.csharp)
  • Monitor Pages Availability
    ... Sometimes our Outlook Web Access becomes unavailable although IIS appears to ... to the interface, accessing a page, and logging out again? ... I'm not a programmer so it would have to be "out of the ...
    (microsoft.public.inetserver.iis)