lib/logstasher.rb in logstasher-1.0.1 vs lib/logstasher.rb in logstasher-1.1.0
- old
+ new
@@ -15,11 +15,11 @@
extend self
STORE_KEY = :logstasher_data
REQUEST_CONTEXT_KEY = :logstasher_request_context
attr_accessor :logger, :logger_path, :enabled, :log_controller_parameters, :source, :backtrace,
- :controller_monkey_patch
+ :controller_monkey_patch, :field_renaming
# Setting the default to 'unknown' to define the default behaviour
@source = 'unknown'
# By default log the backtrace of exceptions
@backtrace = true
@@ -110,10 +110,11 @@
self.source = config.source unless config.source.nil?
self.log_controller_parameters = !! config.log_controller_parameters
self.backtrace = !! config.backtrace unless config.backtrace.nil?
self.set_data_for_rake
self.set_data_for_console
+ self.field_renaming = Hash(config.field_renaming)
end
def set_data_for_rake
self.request_context['request_id'] = ::Rake.application.top_level_tasks if self.called_as_rake?
end
@@ -175,9 +176,12 @@
end
end
def build_logstash_event(data, tags)
+ field_renaming.each do |old_name, new_name|
+ data[new_name] = data.delete(old_name) if data.key?(old_name)
+ end
::LogStash::Event.new(data.merge('source' => self.source, 'tags' => tags))
end
def store
if RequestStore.store[STORE_KEY].nil?