Rails4与弹性搜索日志记录的生产问题



我正在Heroku上用ruby 2.5.0在rails 4.2.11.3应用程序中实现Elasticsearch,用于用户模型的基本搜索。在heroku暂存环境中,它工作得很好,但在生产环境中,我在导入模型时遇到了这个错误。

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

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

我知道Logger::SimpleFormatter已从rails 4.1中删除,我应该使用ActiveSupport::Logger::SimpleFormatter。我知道生产log_formatter默认为Logger::formatter。我在config/environments/production.rb中尝试了许多配置变体,但都没有成功,还添加了rails_12factor gem,它将rails.logger切换为:

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

如果我引入我自己的Logger::SimpleFormatter类,继承自ActiveSupport::Logger:;SimpleFormatter,它解决了问题,但错误转移到:

undefined class/module Logger::LogDevice::LogDeviceMutex

问题是我们在数据库中有遗留的Braintree对象,当我们执行ES导入时,这些对象正在调用rails 3记录器

最新更新