lib/logstasher.rb in logstasher-0.6.1 vs lib/logstasher.rb in logstasher-0.6.2

- old
+ new

@@ -8,22 +8,24 @@ module LogStasher extend self STORE_KEY = :logstasher_data REQUEST_CONTEXT_KEY = :logstasher_request_context - attr_accessor :logger, :logger_path, :enabled, :log_controller_parameters, :source + attr_accessor :logger, :logger_path, :enabled, :log_controller_parameters, :source, :backtrace # Setting the default to 'unknown' to define the default behaviour @source = 'unknown' + # By default log the backtrace of exceptions + @backtrace = true def remove_existing_log_subscriptions ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber| - case subscriber - when ActionView::LogSubscriber + case subscriber.class.name + when 'ActionView::LogSubscriber' unsubscribe(:action_view, subscriber) - when ActionController::LogSubscriber + when 'ActionController::LogSubscriber' unsubscribe(:action_controller, subscriber) - when ActionMailer::LogSubscriber + when 'ActionMailer::LogSubscriber' unsubscribe(:action_mailer, subscriber) end end end @@ -87,10 +89,11 @@ self.logger = app.config.logstasher.logger || new_logger(self.logger_path) self.logger.level = app.config.logstasher.log_level || Logger::WARN self.source = app.config.logstasher.source unless app.config.logstasher.source.nil? self.enabled = true self.log_controller_parameters = !! app.config.logstasher.log_controller_parameters + self.backtrace = !! app.config.logstasher.backtrace unless app.config.logstasher.backtrace.nil? end def suppress_app_logs(app) if configured_to_suppress_app_logs?(app) require 'logstasher/rails_ext/rack/logger' @@ -112,10 +115,10 @@ end def log(severity, msg) if self.logger && self.logger.send("#{severity}?") event = LogStash::Event.new('@source' => self.source, '@fields' => {:message => msg, :level => severity}, '@tags' => ['log']) - self.logger.send severity, event.to_json + self.logger << event.to_json + "\n" end end def store if RequestStore.store[STORE_KEY].nil?