I’m going to tell you a story.

A few days ago I was working on some component which is quite simple but very cohesive. It was fun developing it and see how it’s organized and behaves. I like when the code looks pretty, when there are good names for methods and variables, when it’s very easy to read and when there is nothing to take away. I like simplicity.

Simplicity is the ultimate sophistication.

— Leonardo da Vinci

I write unit tests and I do write logging statements but not too much. I have to say I constantly forget about logging statements what I’m thinking about writing code is business logic, returning values, methods visibility etc. The last thing I’m thinking about is Logging. I know it’s important for OPS but it’s not important at all in my java class where all my business logic is. All I do is almost like this

} catch(XmlException e){
	log.error("Xml document is not well-formed.", e);
	...
}

and that’s actually because I have a snippet in IntelliJ IDEA for this.

So this morning I had a nice piece of working code that I liked. Afternoon we started testing it on QA server and I started getting requests to add more logging because someone is accustomed to see the process and how it’s going in log files. But my process was almost quiet writing to the log only in case of errors.

By the end of today I’ve got my code with more logging statements saying what it’s doing. Now there is a visibility in the log but I don’t like my code anymore. This stuff, I mean logging, is useless for my code which does work. All what logging does is just telling me what I already know it’s just information not really important to me as a developer, it has nothing to do with my business logic. Logging logic does not provide any business functionality; it’s not related to the domain of a business application.

If the logging is not related to the domain of a business application then is there a way to keep it external?

How are you dealing with this? Do you have common practices or standards? What and how do you log?

P.S.

Ruby On Rails framework provides robust logging information but as a developer who’s using this framework I don’t worry about logging at all. It’s provided by the framework. I’m wondering how it’s implemented inside the framework.

Advertisements