Re: Logging - Best Practices
Lew wrote:
Severity is adjusted in the field as problems or concerns arise, and
not fixed at design time.
Rhino wrote:
I'm not sure I'd agree with that. Certainly, the severity of the
event, whatever it is, may be ASSESSED differently in the field than
it was by the developers. For instance, something thought minor by
Logging packages such as java.util.logging and log4j are explicitly designed
and documented to be adjusted in the field. Regardless of your agreement,
people are trained to adjust logging in the field as circumstances dictate.
That's a best practice, and the reality.
developers may be thought a big deal in the field or vice versa. But
The "big deal" in the field is when something stops working correctly.
Until then, DEBUG gives far too much detail for usefulness. After then, it's
mandatory.
Logging levels are not up to the programmer.
the developer still has to assign a severity to each log record that
may be generated and set the levels captured by the logs at
development time. Those choices may be changed later in the life of
That is set by the sysadmin, not the developers.
the system as developers interact with folks in the field but the
developer is surely going to make the initial decision, hopefully in
consultation with folks in the field.
Nope.
2. Should there be a separate log for log records written by common code,
That depends. Consider if you were the sysadmin for the project in
production. Where would you look for logs?
I'm really not sure where a sysadmin in a large (or even small)
organization would look. I haven't deployed a lot of Java applications
that used logging. Also, I'd expect that each organization would be
different in terms of where a sysadmin would expect to look. That, of
course, makes my question very difficult to answer. I don't expect a
simple, definitive answer that would fit every organization. I'm
mostly just trying to get a feel for where a typical sysadmin in a
typical organization would expect to look.
How about the "logs" directory?
So, for example, if the Baz system calls a class from a common module
to display a date in a particular obscure format and that common class
generates a relatively severe log record, should that record be
written only to a log set up for the common code alone? Or would it be
No.
better to write it to a log associated with the application? I'm
Yes.
strongly inclined to favour the latter. Of course, since that common
code might be called from several different applications, which might
well be in very packages, I'm assuming that a reference to the logger
would need to be passed to the common code so that it knew which log
to write to. On the other hand, if the log records from the common
That's not how log configuration works. You set up a log configuration for
the application that encompasses everything, not just the code you wrote but
the Java API, third-party libraries and so on.
classes was always written to its own log, then the log reference
could be generated within the class and not passed from outside.
Huh?
What do you mean by "the log reference"?
What do you mean by "generated within the class"?
What do you mean by "passed from outside"?
Those phrases don't correlate to my experience with logging frameworks,
writing log statements or perusing logs to attempt to solve a problem. Tha
experience is robust.
Fair enough. I appreciate the advice. I agree that it is probably best
to answer these questions by thinking from the sysadmin point of view.
I may just talk to a sysadmin friend to see what what his take is....
Well, good. How else would you expect to get the user's perspective other
than by talking to the user?
Four dots?
--
Lew