#Logging

I was browsing through our code at Schantz were i do my daytime hacking. I found something that’s not unusual in our code base. To be fair it’s not unusual in most codebases.

The issue is logging, and more specific what log level should be used when.

So i’ve decided to give you my take on it.

Error

The error statement should only be used for actual errors. So if the system will fail catastrophically, and there is no known way to recover, a error is written.

Warn

A warning should be logged when a potential issue can make the application not work correctly, but doesn’t make it crash. This could be a 3rd party system that doesn’t respond.

Info

This level is used to print out the flow of your application. Things like batchjob start, batchjob ended etc..

Debug

This is the one I don’t like. So don’t use it :)

Ask yourself why do you want debug statements in your codebase. This indicates that your are unsure on what happens. If that is the case you should write a test that verify the behavior that you expect.

Trace

Pretty much the same as above, just worse.

So this is not rules that are written in stone, but more of a guideline. To be fair i’ve haven’t always followed these guidelines, but i try to.