lib/hedgelog.rb in hedgelog-0.1.5 vs lib/hedgelog.rb in hedgelog-0.1.6

- old
+ new

@@ -1,9 +1,10 @@ # frozen_string_literal: true require 'hedgelog/version' require 'hedgelog/context' require 'hedgelog/scrubber' +require 'hedgelog/normalizer' require 'logger' require 'yajl' class Hedgelog LEVELS = %w(DEBUG INFO WARN ERROR FATAL UNKNOWN).each_with_object({}).with_index do |(v, h), i| @@ -24,11 +25,12 @@ @level = LEVELS[:debug] @channel = nil @logdev = nil @app = nil @scrubber = Hedgelog::Scrubber.new - @channel_context = Hedgelog::Context.new(@scrubber) + @normalizer = Hedgelog::Normalizer.new + @channel_context = Hedgelog::Context.new(@scrubber, @normalizer) if logdev.is_a?(self.class) @channel = logdev else @logdev = Logger::LogDevice.new(logdev, shift_age: shift_age, shift_size: shift_size) @@ -49,11 +51,11 @@ return true if (@logdev.nil? && @channel.nil?) || severity < @level message, context = *yield if block context ||= {} - context = Hedgelog::Context.new(@scrubber, context) unless context.is_a? Hedgelog::Context + context = Hedgelog::Context.new(@scrubber, @normalizer, context) unless context.is_a? Hedgelog::Context context.merge!(@channel_context) context[:message] ||= message return write(severity, context) if @logdev @@ -117,9 +119,10 @@ end def write(severity, context) return true if @logdev.nil? + context.normalize! context.scrub! data = context.merge(default_data(severity)) data[:app] = @app if @app data[:caller] = debugharder(caller[3]) if debug?