lib/logstasher.rb in logstasher-2.1.1 vs lib/logstasher.rb in logstasher-2.1.2

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'logstasher/version' require 'logstasher/active_support/log_subscriber' require 'logstasher/active_support/mailer_log_subscriber' require 'logstasher/active_record/log_subscriber' if defined?(ActiveRecord) require 'logstasher/action_view/log_subscriber' if defined?(ActionView) @@ -107,12 +109,12 @@ suppress_app_logs(config) self.logger_path = config.logger_path || "#{Rails.root}/log/logstash_#{Rails.env}.log" self.logger = config.logger || new_logger(logger_path) logger.level = config.log_level || Logger::WARN 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.log_controller_parameters = !config.log_controller_parameters.nil? + self.backtrace = !config.backtrace.nil? unless config.backtrace.nil? set_data_for_rake set_data_for_console self.field_renaming = Hash(config.field_renaming) end @@ -123,11 +125,11 @@ def set_data_for_console request_context['request_id'] = Process.pid.to_s if called_as_console? end def called_as_rake? - File.basename($0) == 'rake' + File.basename($PROGRAM_NAME) == 'rake' end def called_as_console? defined?(Rails::Console) && true || false end @@ -158,11 +160,11 @@ # LogStasher.info("message", tags:"tag1") # LogStasher.info("message", tags:["tag1", "tag2"]) # LogStasher.info("message", timing:1234) # LogStasher.info(custom1:"yes", custom2:"no") def log(severity, message, additional_fields = {}) - if logger && logger.send("#{severity}?") + if logger&.send("#{severity}?") data = { 'level' => severity } if message.respond_to?(:to_hash) data.merge!(message.to_hash) else @@ -171,10 +173,10 @@ # tags get special handling tags = Array(additional_fields.delete(:tags) || 'log') data.merge!(additional_fields) - logger << build_logstash_event(data, tags).to_json + "\n" + logger << "#{build_logstash_event(data, tags).to_json}\n" end end def build_logstash_event(data, tags)