in reply to Balancing Logging and Code Readability
How to keep the logging from swamping out your code logic is a good question.
One thing I would suggest is that info and debug level logging can replace comments. Just like code, there is no sense duplicating non-code either.
As for the warn and error levels, testing for those cases could mostly be done at the beginning of a function, while you're gathering and validating parameters. Rather than putting a log message in the center of a function where it makes a call, try to move the logging into the function being called. The function was probably written to keep things clear and avoid duplication of code, so you might as well use it to avoid duplication of logging commands too.
If you can keep the conditional logging confined to the beginning/end and thus out of the logic, and then replace one line comments with one line debug/info logging, the code should stay clean. The trick would be learning to read debug-info logging as if it were a comment. Perhaps by adding a rule to the code highlighting in your editor.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Balancing Logging and Code Readability
by saberworks (Curate) on Sep 14, 2009 at 17:24 UTC | |
by BrowserUk (Patriarch) on Sep 14, 2009 at 17:36 UTC | |
by saberworks (Curate) on Sep 14, 2009 at 18:41 UTC | |
by BrowserUk (Patriarch) on Sep 14, 2009 at 19:04 UTC | |
by ack (Deacon) on Sep 17, 2009 at 02:11 UTC | |
by ack (Deacon) on Sep 17, 2009 at 02:08 UTC | |
by dinomite (Sexton) on Sep 15, 2009 at 05:01 UTC | |
by ack (Deacon) on Sep 17, 2009 at 02:16 UTC | |
|
Re^2: Balancing Logging and Code Readability
by ack (Deacon) on Sep 17, 2009 at 02:06 UTC |