I’m interested at what stage in your development do add logging and/or tracing to your applications?
I’m working with a .Net stack and log4net (via commons.logging). Generally taking a TDD approach to development although admittedly not 100%, sometimes Im know to spike out without test coverage. My application all sit server-side, e.g. web services, windows service that consume messages off a bus, asp.net mvc business admin apps. etc..
I found myself decorating methods in my applicatiosn services with descriptive logger.INFO “Getting cakes from repository” . some work .. “Got 5 cakes from repository. “, and then an unhandled expcetion handler for the app doamin to logger.FATAL for unexpected excpetions that bubble up.
However I usually end up going back and applying these near the end of development rather than at the start of development and I might have a dozen or two only. I find I rarely decorate any lower level classes such as implementation of ICakeRepository with logger stuff as it seems pointless.
For tracing, which switched on via config, I’m thinking of intercepting method calls and instance creation using the IOC framework, and this should take care of on-site troublehsooting rather than heavy trace population.
My software is in layers, with a well-defined API between each layer. I tend to implement logging for those APIs from the begining, so that for any given transaction I can see how that results in an API call at each of the underlying layers: if there’s a mistake, that will help to narrow it down to a specific layer. The logging will also help to reproduce a problem by showing a log of all the previous, normal activity which led up to the problem.
I also add assertions within each layer where I can, and log assertion failures.
A log file therefore often shows of a sequence of calls to the public APIs, with an error message generated from inside: that’s often enough to diagnose the problem.
Beyond that, I add debug-level logging on an as-needed basis: to debug specific problems during development and/or after release.
My reasoning for caring about logging is partly explained in the following:
To fix any bug in released software, I depend on the log file; and the same is also often true of software as it’s being developed.
You said,
I said,
I think I’d better explain what I mean by “layers”, which may or may not be the same as your “lower level” classes.
For example, my system might have the following layers:
In that case I would have the following interfaces or APIs, which might deserve logging:
Alternatively the system might be a chain of components connecting two peer end-points (less obviously with “top” and “bottom” layers).
In any case, what I’m logging is the API that’s each component’s public facade, which is good for logging for several reasons: