Logs are colorized regardless of `colorized_logging` do to load order requirements of dotenv
Author: davetron5000Created Nov 18, 2024Updated Dec 12, 2024
Steps to reproduce
- Make as new Rails app
- add
config.colorize_logging = falsetoconfig/environments/development.rb - Set up some
.envfiles - Start Rails
- Look at the log
Expected behavior
Log messages issued by this gem should respect the colorize_logging value in general, or in this case, not colorize its log output.
Actual behavior
dotenv's initial log messasges are colorized because dotenv loads itself and the .env files before the Rails configuration has taken place to turn off colorized logging.
[dotenv] Set ^[[36mDATABASE_URL^[[0m
[dotenv] Loaded ^[[33m.env.development^[[0mSystem configuration
dotenv version: 3.1.4
Rails version: 8.0.0
Ruby version: 3.3.6
Notes
I don't see a way to tell Rails to avoid colorized logging any earlier.
I can think of two solutions:
- Change these log messages to debug - they don't seem necessary to be at info level
- Change the logging calls to avoid
coloraltogether
Maybe there is a better third option I'm not thinking of?
Source: bkeepers/dotenv