lib/logstasher.rb in logstasher-0.4.9 vs lib/logstasher.rb in logstasher-0.5.0
- old
+ new
@@ -4,11 +4,13 @@
require 'active_support/core_ext/string/inflections'
require 'active_support/ordered_options'
module LogStasher
extend self
- attr_accessor :logger, :enabled, :log_controller_parameters
+ attr_accessor :logger, :enabled, :log_controller_parameters, :source
+ # Setting the default to 'unknown' to define the default behaviour
+ @source = 'unknown'
def remove_existing_log_subscriptions
ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
case subscriber
when ActionView::LogSubscriber
@@ -52,10 +54,11 @@
require 'logstash-event'
self.suppress_app_logs(app)
LogStasher::RequestLogSubscriber.attach_to :action_controller
self.logger = app.config.logstasher.logger || new_logger("#{Rails.root}/log/logstash_#{Rails.env}.log")
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
end
def suppress_app_logs(app)
@@ -76,13 +79,12 @@
def custom_fields=(val)
Thread.current[:logstasher_custom_fields] = val
end
-
def log(severity, msg)
if self.logger && self.logger.send("#{severity}?")
- event = LogStash::Event.new('@fields' => {:message => msg, :level => severity},'@tags' => ['log'])
+ event = LogStash::Event.new('@source' => self.source, '@fields' => {:message => msg, :level => severity}, '@tags' => ['log'])
self.logger.send severity, event.to_json
end
end
%w( fatal error warn info debug unknown ).each do |severity|