1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Adjust The Production Log Level as a Rails TIL

This commit is contained in:
jbranchaud
2025-02-26 16:52:13 -06:00
parent 2b38e1caf8
commit fc74264040
2 changed files with 35 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1601 TILs and counting..._
_1602 TILs and counting..._
See some of the other learning resources I work on:
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -961,6 +961,7 @@ See some of the other learning resources I work on:
- [Add ActiveRecord Error Not Tied To Any Attribute](rails/add-activerecord-error-not-tied-to-any-attribute.md)
- [Add React With Webpacker To A New Rails App](rails/add-react-with-webpacker-to-a-new-rails-app.md)
- [Add timestamptz Columns With The Migration DSL](rails/add-timestamptz-columns-with-the-migration-dsl.md)
- [Adjust The Production Log Level](rails/adjust-the-production-log-level.md)
- [Access Secrets In A Rails 5.2 App](rails/access-secrets-in-a-rails-5-2-app.md)
- [ActiveRecord Query For This Or That](rails/active-record-query-for-this-or-that.md)
- [Advance The Date](rails/advance-the-date.md)

View File

@@ -0,0 +1,33 @@
# Adjust The Production Log Level
A Rails app by default takes on the `debug` log level. This is great for
development because it spits out a lot of information as you build and debug.
That's going to typically be a bit too noisy for a production environment
though. That is why Rails ships with the `config/environments/production.rb`
file configured to the `info` log level.
```ruby
# config/environments/production.rb
Rails.application.configure do
# ...
# "info" includes generic and useful information about system operation, but avoids logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII). If you
# want to log everything, set the level to "debug".
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
# ...
end
```
Sometimes, like when we're trying to track down some buggy behavior, we may
want to switch Rails from one log level to another. That's why it is configured
by the `RAILS_LOG_LEVEL` env var and otherwise falls back to `info`.
To, for example, switch production over to the `debug` log level, we'd first
change the `RAILS_LOG_LEVEL` env var to `debug`. Then we'd need to make sure
our Rails app is restarted so that the config change is picked up. Heroku's
`heroku config:set` will do that automatically. Depending on your setup, you
may need to manually restart your web server (e.g. Puma).