A methodology for logging in production

31 January 2008 | Uncategorized | 1 Comment

This isn’t about how Ops deals with giant syslog servers or logrotate, that stuff is covered elsewhere by people qualified to speak of it. This is a quick crash course on how we as application developers can do logging in a sane way that won’t drive Ops crazy (hopefully) and will help everyone debug issues in production with minimum pain in stressful situations.

The heart of useful logging is using log levels correctly. The reason you have levels is to enable message routing/handling based on importance and also to facilitate easier grepping when it comes to that (and it will). Classic Unix syslog defines these decreasing levels or “priorities”:

So those are the levels, but maybe you’re starting from total scratch and you’ve just been scribbling everything into one big file somewhere. Which levels do you really need to start making things way better?

I think ERR and INFO are the minimum you need to be thinking about when you’re writing your app. What are the normal processing messages that show things are flowing around correctly and in timely fashion (INFO) and what are the major problems and showstoppers that are preventing normal processing of your program (ERR).

You’ll quickly realize that DEBUG is handy for helping detect and verify bugs in QA/dev. WARN might or might not make sense for your environment or might be used very sparingly. You might or might not find uses for the other levels based on the culture of your Ops team, these rules are not hard and fast.

That’s all I know. Go forth and log wisely.

  • http://blog.cbcg.net/ Toby DiPasquale

    Great post! This is some really insightful stuff. Keep it coming :)