In a large application logging is essential, but when many developers work on the code, the logs can become chaotic. One might write:
log.info("Loaded " + rowCount + " recodrs from the database.");
Another might do something like:
log.debug("Records read={}", rowCount);
A third developer might think this is the proper way:
log.trace("Record(s) read: " + NumberFormat.getInstance().format(rowCount)
+ ", values: " + values);
This will result in logs that are hard to read, and much harder to parse.
What guidance can you give developers to produce logs that have a chance to be consistent, and actually be usable by other people? Will a policy about logging do any good? And if so, what should it include? Should there be an API (above the logging framework's own) to enforce this policy?
I'm also curious about how to make the code look alike, but the more important question is about the actual output.
IMHO logging guidelines on what constitutes a good log statement level are rare even among large frameworks and products, primarily due more important guidelines involving
That said, I follow a few general thumb rules at the lowest level:
Standardize the messages, either via API or string formats the developers reference when building the log statements. They shouldn't be typing text like that into the program, even for logging, for exactly the reasons you call out. Naturally, this means you need a policy as well, and reviews to ensure that the policy is respected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With