I was visiting a team a while ago and we came across an area of code with extremely long methods. We looked around and tried to understand the code but its shape and intent was lost in this jungle of run-on statements.
The remedy for this sort of thing is usually very straightforward - you refactor - you select cohesive bits of code and extract them as methods. I was ready to do this, but one of the developers stopped me. "Wait!", he said, "You can't extract that, look at the logging."
I looked and noticed that all of the logging statements were prefaced with the names of the methods they were called from.
I said "Well, we can decide on an alternative or we can preface the calls with the names of the methods we extract." And, they said "No, we count on those names to maintain context. If we extract a method and then call it from someplace else we won't be able to debug our production problems."
I said "You can build nested scopes into your logging."
They said they'd mull it over. We looked at different code.
It was a brief episode, but it reminded me of how much I hate logging. Yes, I realize that it is necessary in many environments, but for me it is definitely in the "necessary evil" category.
Whenever possible, I like to restrict logging to particular level in a design. When it runs rampant through code, it makes the code harder to understand, and people are reluctant to change it.
Yes, logging is useful, but it is a very real form of coupling. If you log you have to manage the coupling it induces. If you don't, it will manage you.

Comments (4)
This reminds me an application I "inherited", the logging statements are not only unnecessary, but also too long - even longer than the statements to do the real jobs.
Posted by Anonymous | April 11, 2008 6:35 PM
Sounds like a real joy of a project to work on.
What kind of debugging are they doing with logs? Can I venture a guess that this might be a slightly dated j2ee app? When you say debug, do you really mean debug or more of a postmortem analysis?
The best is when people have changed the code and left the now irrelevant logging.
If you are really need to debug problems in a running production environment, you can't beat dynamic instrumentation. Thank you DTrace!
Posted by Andrew Shafer | April 12, 2008 5:34 AM
Good point, Mr. Feathers!
I also often felt that the logging, while useful in tracking issues sometimes, it cluttered the working code at the same time, so as to distract me from reading the code that actually does the work. And after finally working out what the code was actually doing, and making some changes to fix or improve it, I sometimes (though I hate to admit) forgot to edit the log messages because I've been trying to not look at the logging code in order to focus on the business code. And hence that problem Andrew pointed out above, "The best is when people have changed the code and left the now irrelevant logging." They are indeed the "best". Yikes!
Posted by Timothy | April 13, 2008 7:44 PM
Working on a big enterprise system has taught me to like logging - it gives me the information I need without the need to restart the system/step through stuff in a debugger or otherwise hinder normal usage of the system. As I log method entry and exit, I always know where a method gets called from, so method extraction is a good thing - it gives me more logging data.
Posted by llogiq | April 15, 2008 6:03 AM