0

I am trying to configure my rails application from an external gem. Trying to build a central gem for handling logging related things.I am setting few loggly configs and trying to add custom params in loggly inspired from this post- Custom data to logs

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

But I am getting NoMethodError when i am including this gem in my application

/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)
Rakesh Yadav
  • 369
  • 3
  • 5
  • 19
  • seems like your railtie is loaded before lograge's one – Aleksey Sep 24 '16 at 08:45
  • @Aleksey how do i control that ? – Rakesh Yadav Sep 24 '16 at 08:50
  • right now I am not sure how. I would try to remove `app` method and pass `app` to `initializer` block (like here http://api.rubyonrails.org/classes/Rails/Railtie.html). and also why do you have `Rails.application.configure`? is it required? – Aleksey Sep 24 '16 at 08:53
  • @Aleksey if i put same configs in my development.rb then it is working fine. – Rakesh Yadav Sep 24 '16 at 08:54
  • in `development.rb` you need `configure` method but in railtie I think there is no need. right now I need to go. I will check this question few hours later. – Aleksey Sep 24 '16 at 08:58
  • @Aleksey Thanks for pointing it out. It worked – Rakesh Yadav Sep 24 '16 at 10:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124103/discussion-between-aleksey-and-rakesh-yadav). – Aleksey Sep 24 '16 at 12:59

0 Answers0