Rails Log Level Configurable Via RAILS_LOG_LEVEL In Production

In the latest version of Rails, the production config file comes with logging which is configurable based on an environment variable.

This is a useful because it allows us to change the log level, in production, without a code deploy. Typically we don’t want debug logs on permanently because it creates too much noise. However, it’s useful to enable debug logs temporarily to help trace production bugs.

If you’re not on the latest Rails version, you can still take advantage of this feature by making the following change to your environments/production.rb file:

1
2
- config.log_level = :info
+  config.log_level = ENV.fetch("RAILS_LOG_LEVEL") { "info" }