我正在尝试从外部 gem 配置我的 rails 应用程序。尝试构建一个中央 gem 来处理与日志相关的事情。我正在设置一些 loggly 配置并尝试在 loggly 中添加自定义参数,灵感来自这篇文章自定义数据到日志
module Bizlogger
class Railtie < Rails::Railtie # :nodoc:
initializer 'bizlogger.configure_rails_initialization' do
config = app.config
Rails.application.configure do
require 'syslogger'
config.lograge.enabled = true
config.lograge.custom_payload = proc do
{
host: request.host,
user_id: current_user.try(:id),
fwd: request.remote_ip
}
end
end
app.middleware.insert_before Rails::Rack::Logger, Bizlogger::Middleware,
{}
end
def app #:nodoc:
Rails.application
end
end
end
但是当我在我的应用程序中包含这个 gem 时,我得到了 NoMethodError
/home/rakesh/.rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `lograge' for #<Rails::Application::Configuration:0x00000003959040> (NoMethodError)