Skip to content

Commit

Permalink
Remove dump_stacktrace from delegators because it has own log level
Browse files Browse the repository at this point in the history
  • Loading branch information
repeatedly committed Feb 3, 2014
1 parent cde3862 commit 2238c38
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/fluent/log.rb
Expand Up @@ -50,6 +50,7 @@ def initialize(out=STDERR, level=LEVEL_TRACE, opts={})
@self_event = false
@tag = 'fluent'
@time_format = '%Y-%m-%d %H:%M:%S %z '
@depth_offset = 1
enable_color out.tty?
# TODO: This variable name is unclear so we should change to better name.
@threads_exclude_events = []
Expand Down Expand Up @@ -114,7 +115,7 @@ def trace(*args, &block)
return if @level > LEVEL_TRACE
args << block.call if block
time, msg = event(:trace, args)
puts [@color_trace, caller_line(time, 1, LEVEL_TRACE), msg, @color_reset].join
puts [@color_trace, caller_line(time, @depth_offset, LEVEL_TRACE), msg, @color_reset].join
rescue
# logger should not raise an exception. This rescue prevents unexpected behaviour.
end
Expand All @@ -133,7 +134,7 @@ def debug(*args, &block)
return if @level > LEVEL_DEBUG
args << block.call if block
time, msg = event(:debug, args)
puts [@color_debug, caller_line(time, 1, LEVEL_DEBUG), msg, @color_reset].join
puts [@color_debug, caller_line(time, @depth_offset, LEVEL_DEBUG), msg, @color_reset].join
rescue
end
alias DEBUG debug
Expand All @@ -151,7 +152,7 @@ def info(*args, &block)
return if @level > LEVEL_INFO
args << block.call if block
time, msg = event(:info, args)
puts [@color_info, caller_line(time, 1, LEVEL_INFO), msg, @color_reset].join
puts [@color_info, caller_line(time, @depth_offset, LEVEL_INFO), msg, @color_reset].join
rescue
end
alias INFO info
Expand All @@ -169,7 +170,7 @@ def warn(*args, &block)
return if @level > LEVEL_WARN
args << block.call if block
time, msg = event(:warn, args)
puts [@color_warn, caller_line(time, 1, LEVEL_WARN), msg, @color_reset].join
puts [@color_warn, caller_line(time, @depth_offset, LEVEL_WARN), msg, @color_reset].join
rescue
end
alias WARN warn
Expand All @@ -187,7 +188,7 @@ def error(*args, &block)
return if @level > LEVEL_ERROR
args << block.call if block
time, msg = event(:error, args)
puts [@color_error, caller_line(time, 1, LEVEL_ERROR), msg, @color_reset].join
puts [@color_error, caller_line(time, @depth_offset, LEVEL_ERROR), msg, @color_reset].join
rescue
end
alias ERROR error
Expand All @@ -205,7 +206,7 @@ def fatal(*args, &block)
return if @level > LEVEL_FATAL
args << block.call if block
time, msg = event(:fatal, args)
puts [@color_fatal, caller_line(time, 1, LEVEL_FATAL), msg, @color_reset].join
puts [@color_fatal, caller_line(time, @depth_offset, LEVEL_FATAL), msg, @color_reset].join
rescue
end
alias FATAL fatal
Expand Down Expand Up @@ -237,11 +238,12 @@ def dump_stacktrace(backtrace, level)
return if @level > level

time = Time.now
line = caller_line(time, 5, level)
if @suppress_repeated_stacktrace && (Thread.current[:last_repeated_stacktrace] == backtrace)
puts [" ", caller_line(time, 5, level), 'suppressed same stacktrace'].join
puts [" ", line, 'suppressed same stacktrace'].join
else
backtrace.each { |msg|
puts [" ", caller_line(time, 5, level), msg].join
puts [" ", line, msg].join
}
Thread.current[:last_repeated_stacktrace] = backtrace if @suppress_repeated_stacktrace
end
Expand Down Expand Up @@ -304,6 +306,9 @@ class PluginLogger < Log
def initialize(logger)
@logger = logger
@level = @logger.level
@depth_offset = 2
@suppress_repeated_stacktrace = logger.instance_variable_get(:@suppress_repeated_stacktrace)

enable_color @logger.enable_color?
end

Expand All @@ -329,7 +334,7 @@ def enable_color(b = true)
extend Forwardable
def_delegators '@logger', :enable_color?, :enable_debug, :enable_event,
:disable_events, :tag, :tag=, :time_format, :time_format=,
:event, :dump_stacktrace, :caller_line, :puts, :write, :flush
:event, :caller_line, :puts, :write, :flush
end


Expand Down

0 comments on commit 2238c38

Please sign in to comment.