lib/hedgelog.rb in hedgelog-0.1.13.alpha.1 vs lib/hedgelog.rb in hedgelog-0.2.0
- old
+ new
@@ -23,16 +23,16 @@
BACKTRACE_RE = Regexp.new("([^:]+):([0-9]+)(?::in `(.*)')?")
attr_reader :level
attr_writer :app
- def initialize(logdev = $stdout, shift_age = nil, shift_size = nil)
+ 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
+ @scrubber = Hedgelog::Scrubber.new(cleaner)
@normalizer = Hedgelog::Normalizer.new
@channel_context = Hedgelog::Context.new(@scrubber, @normalizer)
if logdev.is_a?(self.class)
@channel = logdev
@@ -46,11 +46,10 @@
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 ||= {}
@@ -61,11 +60,10 @@
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
@@ -147,11 +145,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)
{
@@ -176,10 +174,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..]
+ path[whence.length + 1..-1]
else
# We get here if the path is not in $:
path
end