lib/hedgelog.rb in hedgelog-0.1.2 vs lib/hedgelog.rb in hedgelog-0.1.3

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true require 'hedgelog/version' require 'hedgelog/context' require 'hedgelog/scrubber' require 'logger' require 'yajl' @@ -11,12 +12,12 @@ h[v.to_sym] = i h[v.downcase.to_sym] = i h[i] = v.downcase.to_sym end.freeze - TOP_LEVEL_KEYS = [:app, :channel, :level, :level_name, :message, :request_id, :timestamp] - RESERVED_KEYS = [:app, :level, :level_name, :timestamp, :context, :caller] + TOP_LEVEL_KEYS = [:app, :channel, :level, :level_name, :message, :request_id, :timestamp].freeze + RESERVED_KEYS = [:app, :level, :level_name, :timestamp, :context, :caller].freeze TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%S.%6N%z'.freeze BACKTRACE_RE = /([^:]+):([0-9]+)(?::in `(.*)')?/ def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil) @@ -45,11 +46,11 @@ attr_writer :app def add(severity = LEVELS[:unknown], message = nil, progname = nil, context, &block) return true if (@logdev.nil? && @channel.nil?) || severity < @level - message, context = *block.call if block + message, context = *yield if block context ||= {} context = Hedgelog::Context.new(@scrubber, context) unless context.is_a? Hedgelog::Context context.merge!(@channel_context) context[:message] ||= message @@ -124,10 +125,11 @@ data[:app] = @app if @app data[:caller] = debugharder(caller[3]) if debug? data = extract_top_level_keys(data) @logdev.write(Yajl::Encoder.encode(data) + "\n") + true end def default_data(severity) { timestamp: Time.now.strftime(TIMESTAMP_FORMAT), @@ -148,16 +150,16 @@ def debugharder(callinfo) m = BACKTRACE_RE.match(callinfo) return unless m path, line, method = m[1..3] whence = $LOAD_PATH.find { |p| path.start_with?(p) } - if whence - # Remove the RUBYLIB path portion of the full file name - file = path[whence.length + 1..-1] - else - # We get here if the path is not in $: - file = path - end + file = if whence + # Remove the RUBYLIB path portion of the full file name + path[whence.length + 1..-1] + else + # We get here if the path is not in $: + path + end { file: file, line: line, method: method