Logging

Remaing well informed at all time 🤓

Log levels

Rails offers six different log levels (debug, info, warn, error, fatal, and unknown), in increasing severity order. Here are the levels we use at Seraphin and in which situation we use them:

Log level

Use case

debug

No intervention needed

Our application is working fine, we just want to log information in order to retrieve it later if needed, but we don't want to be notified about those logs. This is the level we use to be informed about third-parties services or API crashing, when those events are still within the bounds of expected or known behavior, and we know we have no control over it.

info

Most of the time, no intervention is needed

Our application is working fine as intended, but we want to log usefull business or technical information so we can retrieve it later and be notified. "Business bugs" should normally always be here since there is nothing going wrong on a tech point of view.

warn

Intervention probably needed

We use this intermediary level to get informed when something goes wrong and we want to draw our attention that an intervention might be needed.

error

Intervention needed

We use this level to capture things that are out of the ordinary, mainly internal bugs that we know can occasionaly happen and for which an intervention from IT will certainly be needed. This is used for example when a client happen to be in a situation where he's not supposed to be: we want to be notified and we usually use a rescue clause so that the user doesn't end up on an error page.

We don't use the more-critical fatal log level : when we reach the point where we intentionally want our application to crash (meaning we don't rescue the error and the user ends up on an error page), our crash-reporting solution takes over and notify us with a fully detailed bug report.

DevLog module

In our application, we use our special DevLog module, which allows us to easily print logs from anywhere in the code with the desired severity level. Invoking this module is very straightforward:

DevLog.debug("MESSAGE)
DevLog.info("MESSAGE)
DevLog.warn("MESSAGE")
DevLog.error("MESSAGE")

This is basically an override of Rails.logger.info that prepends a given prefix to the log. This enables us to easily track down those logs in our log management system and to be informed in a granular fashion by our notification system.

There is therefore no point in using Rails.logger anywhere in the code...the messages will just get swallowed in the vast sea of logs. Use our dedicated module instead, and you'll be sure to get notified.

Last updated