shadabahmed / logstasher

Awesome rails logs
MIT License
821 stars 136 forks source link

custom fields don't show up in log entries #93

Open ctaintor opened 8 years ago

ctaintor commented 8 years ago

There's a bug in 0.8 where, if you set custom_fields, they will be cleared before they are really used. The problem is that all three log subscribers (ActiveRecord, ActionView, ActionController) have this line:

LogStasher.custom_fields.clear

practically, this means that you will only see custom fields on your ActionController log entries if you have no view rendering or AR calls, since those calls will cause their associated log subscriber to clear the custom_fields array. This isn't very useful.

A temporary workaround is to just disable the new log subscribers like so in your config/logstasher.rb

  ::ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
    case subscriber.class.name
      when 'LogStasher::ActionView::LogSubscriber'
        LogStasher.unsubscribe(:action_view, subscriber)
      when 'LogStasher::ActiveRecord::LogSubscriber'
        LogStasher.unsubscribe(:active_record, subscriber)
    end
  end