bkeepers / dotenv

A Ruby gem to load environment variables from `.env`.
MIT License
6.61k stars 505 forks source link

Logs are colorized regardless of `colorized_logging` do to load order requirements of dotenv #514

Open davetron5000 opened 6 days ago

davetron5000 commented 6 days ago

Steps to reproduce

  1. Make as new Rails app
  2. add config.colorize_logging = false to config/environments/development.rb
  3. Set up some .env files
  4. Start Rails
  5. 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^[[0m

System 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:

Maybe there is a better third option I'm not thinking of?