lib/hedgelog.rb in hedgelog-0.2.1.alpha1 vs lib/hedgelog.rb in hedgelog-0.2.1.alpha.2
- old
+ new
@@ -23,11 +23,12 @@
BACKTRACE_RE = Regexp.new("([^:]+):([0-9]+)(?::in `(.*)')?")
attr_reader :level
attr_writer :app
- def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil, cleaner = nil)
+ # rubocop:disable Metrics/ParameterLists
+ def initialize(logdev = $stdout, shift_age = nil, shift_size = nil, cleaner = nil)
@level = LEVELS[:debug]
@channel = nil
@logdev = nil
@app = nil
@scrubber = Hedgelog::Scrubber.new(cleaner)
@@ -38,18 +39,20 @@
@channel = logdev
else
@logdev = Logger::LogDevice.new(logdev, shift_age: shift_age, shift_size: shift_size)
end
end
+ # rubocop:enable Metrics/ParameterLists
def level=(level)
int_level = level_to_int(level)
raise ::ArgumentError, "#{self.class}#level= , #{level} is not a valid level." if int_level.nil?
@level = int_level
end
+ # rubocop:disable Metrics/ParameterLists
def add(severity = LEVELS[:unknown], message = nil, progname = nil, context = {}, &block)
return true if (@logdev.nil? && @channel.nil?) || severity < @level
message, context = *yield if block
context ||= {}
@@ -60,10 +63,11 @@
return write(severity, context) if @logdev
@channel&.add(severity, nil, progname, context)
end
+ # rubocop:enable Metrics/ParameterLists
def []=(key, val)
@channel_context[key] = val
end
@@ -145,11 +149,11 @@
data = context.merge(default_data(severity))
data[:app] = @app if @app
data[:caller] = debugharder(caller(4, 1).first) if debug?
data = extract_top_level_keys(data)
- @logdev.write(Yajl::Encoder.encode(data) + "\n")
+ @logdev.write("#{Yajl::Encoder.encode(data)}\n")
true
end
private def default_data(severity)
{
@@ -174,10 +178,10 @@
path, line, method = m[1..3]
whence = $LOAD_PATH.find { |p| path.start_with?(p) }
file = if whence
# Remove the RUBYLIB path portion of the full file name
- path[whence.length + 1..-1]
+ path[whence.length + 1..]
else
# We get here if the path is not in $:
path
end