lib/insque/json_logger.rb in insque-0.7.0 vs lib/insque/json_logger.rb in insque-0.7.1

- old
+ new

@@ -1,12 +1,18 @@ module Insque class JsonLogger < ::Logger attr_accessor :additional_fields + def initialize(logdev, level: INFO, sync: true, additional_fields: {}) + super logdev + self.level = level + logdev.sync = sync if logdev.respond_to?(:sync=) + @default_formatter = JsonFormatter.new + @additional_fields = additional_fields + end + def format_message(severity, datetime, progname, msg) - @json_formatter ||= JsonFormatter.new - @additional_fields ||= {} - (@formatter || @json_formatter).call(severity, datetime, progname, msg, @additional_fields) + (@formatter || @default_formatter).call(severity, datetime, progname, msg: msg, additional_fields: additional_fields) end private # Severity label for logging (max 5 chars). SEV_LABEL = %w(debug info warn error fatal any).each(&:freeze).freeze