bkeepers / dotenv

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

[BUG] All logs are tagged with "dotenv" #496

Closed n-rodriguez closed 8 months ago

n-rodriguez commented 8 months ago

Hi there!

There is a bug with the latest version of dotenv : all logs are tagged with dotenv

See:

OK => [2024-02-29T23:42:25.526108 #43012 #] DEBUG ["dotenv"] - concerto.rake: Set NODE_ENV, RAILS_MASTER_KEY, SETTINGS.RAILS.SECRET_KEY_BASE, SETTINGS.RAILS.ENABLE_BROWSER_VALIDATIONS, SETTINGS.RAILS.ACTION_ON_STRICT_LOADING_VIOLATION, SETTINGS.POSTGRES.HOST, SETTINGS.POSTGRES.PORT, SETTINGS.POSTGRES.NAME, SETTINGS.POSTGRES.USER, SETTINGS.POSTGRES.PASS, SETTINGS.REDIS.HOST, SETTINGS.REDIS.PORT, SETTINGS.SMTP.HOST, SETTINGS.SMTP.PORT, SETTINGS.SMTP.FROM, SETTINGS.SMTP.DOMAIN, SETTINGS.SMTP.USER, SETTINGS.SMTP.PASS, SETTINGS.MONITORING.STATUS_PAGE.USER, SETTINGS.MONITORING.STATUS_PAGE.PASS, SETTINGS.MONITORING.SENTRY.DSN, SETTINGS.MONITORING.PROMETHEUS.ENABLED, SETTINGS.MONITORING.WARN_EMAIL, SETTINGS.NEWSLETTER.MAILING_LIST_ID, SETTINGS.FROALA.LICENCE_KEY, SETTINGS.FYHER.API_URL, SETTINGS.YOUSIGN.V2.API_KEY, SETTINGS.YOUSIGN.V2.ENVIRONMENT, SETTINGS.YOUSIGN.V2.LOG_LEVEL, SETTINGS.MAILGUN.DOMAIN, SETTINGS.MAILGUN.API_KEY, SETTINGS.GMAP.API_KEY, SETTINGS.GANALYTICS.SITE_TRACKER_FR, SETTINGS.GANALYTICS.SITE_TRACKER_ES, SETTINGS.GOOGLE_TAGS.SITE_TRACKER_FR, SETTINGS.GOOGLE_TAGS.SITE_TRACKER_ES, SETTINGS.GOOGLE_TAGS.SITE_TRACKER_FYHER, SETTINGS.RECAPTCHA.SITE_KEY, SETTINGS.RECAPTCHA.SECRET_KEY, SETTINGS.OVH.SMS.ACCOUNT, SETTINGS.OVH.SMS.SENDER, SETTINGS.OVH.SMS.APPLICATION_KEY, SETTINGS.OVH.SMS.APPLICATION_SECRET, SETTINGS.OVH.SMS.CONSUMER_KEY, DISABLE_DATABASE_ENVIRONMENT_CHECK, SETTINGS.MONITORING.ICINGA.HOST, SETTINGS.MONITORING.ICINGA.USER, SETTINGS.MONITORING.ICINGA.PASS, SETTINGS.MONITORING.ICINGA.NODE, SETTINGS.MONITORING.ICINGA.AUTHOR, SETTINGS.MONITORING.GRAFANA.HOST, SETTINGS.MONITORING.GRAFANA.TOKEN, SHAKAPACKER_ASSET_HOST, SETTINGS.RAILS.SERVE_STATIC_FILES, SETTINGS.CAPYBARA.HEADLESS, SETTINGS.LOG.SPLIT_RAILS_LOGGER, SETTINGS.LOG.LOGGERS.RAILS_CACHE.LOG_LEVEL, and GITLAB_TOKEN
OK =>  [2024-02-29T23:42:25.526427 #43012 #]  INFO ["dotenv"] - concerto.rake: Loaded .env.local
OK =>  [2024-02-29T23:42:25.526455 #43012 #]  INFO ["dotenv"] - concerto.rake: Loaded .env.local
NOK => [2024-02-29T23:42:26.054844 #43012 #] DEBUG ["dotenv"] - concerto.rake:   SQL (4.4ms)  SELECT "regions"."id" AS t0_r0, "regions"."created_at" AS t0_r1, "regions"."updated_at" AS t0_r2, "regions"."country_id" AS t0_r3, "regions"."map_identifier" AS t0_r4, "regions"."latitude" AS t0_r5, "regions"."longitude" AS t0_r6, "regions"."attachment_data" AS t0_r7, "regions"."subdivisions" AS t0_r8, "regions"."on_french_site" AS t0_r9, "region_translations"."id" AS t1_r0, "region_translations"."region_id" AS t1_r1, "region_translations"."locale" AS t1_r2, "region_translations"."created_at" AS t1_r3, "region_translations"."updated_at" AS t1_r4, "region_translations"."slug" AS t1_r5, "region_translations"."name" AS t1_r6, "countries"."id" AS t2_r0, "countries"."name" AS t2_r1, "countries"."created_at" AS t2_r2, "countries"."updated_at" AS t2_r3, "countries"."country_code" AS t2_r4 FROM "regions" LEFT OUTER JOIN "region_translations" ON "region_translations"."region_id" = "regions"."id" LEFT OUTER JOIN "countries" ON "countries"."id" = "regions"."country_id" WHERE "countries"."country_code" = 'FR' AND "regions"."on_french_site" = TRUE /*application='Concerto'*/
NOK => [2024-02-29T23:42:26.055129 #43012 #] DEBUG ["dotenv"] - concerto.rake:   ↳ app/models/region.rb:108:in `for_french_site'
NOK => [2024-02-29T23:42:26.069380 #43012 #] DEBUG ["dotenv"] - concerto.rake:   SQL (1.6ms)  SELECT "regions"."id" AS t0_r0, "regions"."created_at" AS t0_r1, "regions"."updated_at" AS t0_r2, "regions"."country_id" AS t0_r3, "regions"."map_identifier" AS t0_r4, "regions"."latitude" AS t0_r5, "regions"."longitude" AS t0_r6, "regions"."attachment_data" AS t0_r7, "regions"."subdivisions" AS t0_r8, "regions"."on_french_site" AS t0_r9, "translations"."id" AS t1_r0, "translations"."region_id" AS t1_r1, "translations"."locale" AS t1_r2, "translations"."created_at" AS t1_r3, "translations"."updated_at" AS t1_r4, "translations"."slug" AS t1_r5, "translations"."name" AS t1_r6, "countries"."id" AS t2_r0, "countries"."name" AS t2_r1, "countries"."created_at" AS t2_r2, "countries"."updated_at" AS t2_r3, "countries"."country_code" AS t2_r4 FROM "regions" LEFT OUTER JOIN "region_translations" "translations" ON "translations"."region_id" = "regions"."id" LEFT OUTER JOIN "countries" ON "countries"."id" = "regions"."country_id" WHERE "countries"."country_code" = 'FR' AND "regions"."on_french_site" = TRUE AND "translations"."name" = 'Espagne' AND "translations"."locale" = 'fr' /*application='Concerto'*/
NOK => [2024-02-29T23:42:26.069591 #43012 #] DEBUG ["dotenv"] - concerto.rake:   ↳ app/models/region.rb:108:in `for_french_site'

I think this is due to https://github.com/bkeepers/dotenv/blob/588f7a489ebaff737ed31847e39abad9b336f649/lib/dotenv/rails.rb#L96C1-L100C8 (.tagged("dotenv"))

To make the tag not permanent you must use the block form (https://api.rubyonrails.org/classes/ActiveSupport/TaggedLogging.html)

Thank you!

bkeepers commented 8 months ago

@n-rodriguez I'm not able to duplicate. Can you give me more info about your setup and proivde the relevant info from the issue template? Here's a newly generated app:

[dotenv] Set FOO
[dotenv] Loaded .env
Started GET "/" for ::1 at 2024-02-29 17:48:44 -0500
  ActiveRecord::SchemaMigration Load (0.1ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by Rails::WelcomeController#index as HTML
  Rendering /Users/bkeepers/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.1.3.2/lib/rails/templates/rails/welcome/index.html.erb
  Rendered /Users/bkeepers/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.1.3.2/lib/rails/templates/rails/welcome/index.html.erb (Duration: 0.5ms | Allocations: 374)
Completed 200 OK in 7ms (Views: 2.5ms | ActiveRecord: 0.0ms | Allocations: 4219)

And versions:

❯ dotenv --version
dotenv 3.1.0
❯ rails --version
Rails 7.1.3.2
❯ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]