lib/logspot.rb in logspot-0.2.0 vs lib/logspot.rb in logspot-0.3.0
- old
+ new
@@ -3,11 +3,11 @@
class LoGspot
LOG_LEVELS = %w(DEBUG INFO WARN ERROR FATAL)
def initialize(file_name, wrapper = nil)
wrapper = ->(output, data) {
- base = "[#{Time.now.strftime('%Y/%m/%d %H:%M:%S')} #{level[0]}] "
+ base = "[#{Time.now.strftime('%Y/%m/%d %H:%M:%S')} #{level}] "
if data[:space]
base = ' ' * base.length
end
output.puts(message: "#{base}#{data[:message]}")
}
@@ -48,31 +48,31 @@
h.each do |key, value|
tagged_list("#{key}: ".ljust(len), key, value, &block)
end
end
- def value(v, options = {})
+ def value(level, v, options = {})
if v.is_a?(Hash)
hash(v) do |k, v|
- value(v, options)
+ value(level, v, options)
end
elsif v.is_a?(Array)
h = Hash[v.map.with_index do |v, i|
[i.to_s, v]
end]
- value(h, options)
+ value(level, h, options)
else
if p = options[:split_proc]
p.call(v.to_s).each do |line|
- write(@level, line)
+ send(level, line)
end
elsif max = options[:max_columns]
v.to_s.split('').each_slice(max).map { |x| x.join('') }.each do |line|
- write(@level, line)
+ send(level, line)
end
else
- write(@level, v)
+ send(level, v)
end
end
end
def untagged(&block)
@@ -85,21 +85,21 @@
define_method(level.downcase) do |*args, &block|
write(level, *args, &block)
end
end
- def write(l, *args, &block)
- @level = l
- output.puts(message: args[0], args: args, arg_block: block)
- end
-
def finalize
@file.finalize
end
private
attr_reader :original_output, :output, :level
+
+ def write(l, *args, &block)
+ @level = l
+ output.puts(message: args[0], args: args, arg_block: block)
+ end
def wrap_output(block, *args, &wrapper)
previous_output, @output = output, Output::Wrap.new(wrapper, output)
res = block.call(*args)
@output = previous_output