conflict with dotenv gem - ActiveSupport::TaggedLogging Error with dotenv 3.1.7 logging
Hello, I'm not sure if this is a logcraft or logging error but thought I would post an issue here first.
I added this to my Gemfile:
gem 'logcraft'
(No other changes.)
That causes this error:
/Users/ndbroadbent/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/activesupport-7.0.8.7/lib/active_support/tagged_logging.rb:77:in `extended': can't modify frozen NilClass: nil (FrozenError)
from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/activesupport-7.0.8.7/lib/active_support/tagged_logging.rb:103:in `extend'
from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/activesupport-7.0.8.7/lib/active_support/tagged_logging.rb:103:in `tagged'
from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/dotenv-3.1.7/lib/dotenv/rails.rb:96:in `block in <class:Rails>'
from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/railties-7.0.8.7/lib/rails/initializable.rb:32:in `instance_exec'
from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/railties-7.0.8.7/lib/rails/initializable.rb:32:in `run'
from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/railties-7.0.8.7/lib/rails/initializable.rb:61:in `block in run_initializers'
from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.3.6/lib/ruby/3.3.0/tsort.rb:231:in `block in tsort_each'
from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.3.6/lib/ruby/3.3.0/tsort.rb:353:in `block (2 levels) in each_strongly_connected_component'
...
The dotenv gem does this:
initializer 'dotenv', after: :initialize_logger do |app|
self.logger = ActiveSupport::TaggedLogging.new(::Rails.logger).tagged('dotenv') if logger.is_a?(ReplayLogger)
end
Crash is happening in /lib/active_support/tagged_logging.rb when it calls logger.formatter.extend (because logger.formatter is nil):
def tagged(*tags)
if block_given?
formatter.tagged(*tags) { yield self }
else
logger = ActiveSupport::TaggedLogging.new(self)
logger.formatter.extend LocalTagStorage
logger.push_tags(*formatter.current_tags, *tags)
logger
end
end
I saw this rails_compat file in the logging gem. It defines a formatter method that just return nil:
https://github.com/TwP/logging/blob/master/lib/logging/rails_compat.rb#L12
I thought I would post here because it feels like logcraft does a bit more to ensure compatibility with Rails apps, while logging is a more general-purpose library.
Off-topic - does logcraft play nice with the logstop gem? https://github.com/ankane/logstop Would like to keep using that too.
Hi @ndbroadbent ,
Sorry I didn't have time to look into this issue. I'm off on working on completely different projects and haven't really had time to work on Logcraft (or any Ruby/Rails projects) for a while now. I need to ask for some more patience if you can't find the solution on your own.
Thanks, Z