Appropriately Using Logger

Hey all,

This is both an Elixir question and a General programming question.

I was wondering if anybody out there has any resources on how to appropriately use the Logger in both development and production environments. I understand log levels and how the logger in elixir works; I’m looking more for best practices on using it.

I’m looking for articles, resources, etc. to teach me what to log/how to log appropriately.

My basic question is: What do you log in your application? Do you have any examples?

:wave:

Check out “Good Logging” section on https://ferd.ca/erlang-otp-21-s-new-logger.html

3 Likes

To paraphrase Einstein, “Log enough to debug something in production and no more”

Now that Prometheus is getting more popular we have also dropped some logging in favor of using Prometheus. These were logs we would post-process for timings/metrics.

At the topmost level you want logs that

  1. prompt Support to intervene i.e. criticals e.g. invalid account credited.
  2. indicate the system just transitions out off normal status i.e. warnings e.g. warehouse inventory system unreachable, warehouse inventory system reachable.
  3. general system transitions i.e. info e.g. new order received, order resolved, warehouse inventory system reachable.

Due to tracing getting logs right the first time isn’t as major as you might think. You always have the option of turning tracing on, collect trace logs and turning tracing off at runtime.

3 Likes