'Rails 4 production issue with elasticsearch logging
I am implementing Elasticsearch on Heroku in a rails 4.2.11.3 app with ruby 2.5.0 for basic search of the User model. In the heroku staging environment, it works perfectly, but in the production environment, I am encountering this error when importing the model.
irb(main):001:0> User.import
Traceback (most recent call last):
16: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:16:in `visit'
15: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:208:in `visit_Psych_Nodes_Mapping'
14: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:374:in `revive'
13: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:336:in `revive_hash'
12: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:336:in `each_slice'
11: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:336:in `each'
10: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:338:in `block in revive_hash'
9: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:32:in `accept'
8: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:6:in `accept'
7: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/visitor.rb:16:in `visit'
6: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:208:in `visit_Psych_Nodes_Mapping'
5: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/visitors/to_ruby.rb:391:in `resolve_class'
4: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/class_loader.rb:28:in `load'
3: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/class_loader.rb:46:in `find'
2: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/class_loader.rb:54:in `resolve'
1: from /app/vendor/ruby-2.5.0/lib/ruby/2.5.0/psych/class_loader.rb:54:in `path2class'
ArgumentError (undefined class/module Logger::SimpleFormatter)
Rails.logger is:
irb(main):002:0> Rails.logger
=> #<ActiveSupport::Logger:0x0000563a356d7070 @level=2, @progname=nil, @default_formatter=#<Logger::Formatter:0x0000563a356d6e40 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x0000563a356d6be8 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x0000563a356d6d78 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x0000563a356d6c88>>, @local_levels=#<ThreadSafe::Cache:0x0000563a356d6ad0 @backend={}, @default_proc=nil>>
I am aware that Logger::SimpleFormatter was removed from rails 4.1, and I should be using ActiveSupport::Logger::SimpleFormatter. I understand that the production log_formatter defaults to Logger::Formatter. I have tried numerous config variations in config/environments/production.rb, to no avail, and also adding the the rails_12factor gem, which switches the Rails.logger to:
<RailsStdoutLogging::StdoutLogger:0x000055fbb41bca28 @level=2, @progname=nil, @default_formatter=#<Logger::Formatter:0x000055fbb41bc988 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x000055fbb41bc8c0 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x000055fbb41bc938 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x000055fbb41bc8e8>>, @local_levels=#<ThreadSafe::Cache:0x000055fbb41bc898 @backend={}, @default_proc=nil>>
If I introduce the my own Logger::SimpleFormatter class, inheriting from ActiveSupport::Logger::SimpleFormatter, it solves the issue, but the error moves to:
undefined class/module Logger::LogDevice::LogDeviceMutex
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
