# File lib/fluent/log.rb, line 56 def initialize(out=STDERR, level=LEVEL_TRACE, opts={}) @out = out @level = level @debug_mode = false @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 = [] if opts.has_key?(:suppress_repeated_stacktrace) @suppress_repeated_stacktrace = opts[:suppress_repeated_stacktrace] end end
# File lib/fluent/log.rb, line 44 def self.str_to_level(log_level_str) case log_level_str.downcase when "trace" then LEVEL_TRACE when "debug" then LEVEL_DEBUG when "info" then LEVEL_INFO when "warn" then LEVEL_WARN when "error" then LEVEL_ERROR when "fatal" then LEVEL_FATAL else raise "Unknown log level: level = #{log_level_str}" end end
# File lib/fluent/log.rb, line 143 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, @depth_offset, LEVEL_DEBUG), msg, @color_reset].join rescue end
# File lib/fluent/log.rb, line 152 def debug_backtrace(backtrace=$!.backtrace) dump_stacktrace(backtrace, LEVEL_DEBUG) end
If you want to suppress event emitting in specific thread, please use this method. Events in passed thread are never emitted.
# File lib/fluent/log.rb, line 115 def disable_events(thread) @threads_exclude_events.push(thread) unless @threads_exclude_events.include?(thread) end
# File lib/fluent/log.rb, line 92 def enable_color(b=true) if b @color_trace = TTYColor::BLUE @color_debug = TTYColor::WHITE @color_info = TTYColor::GREEN @color_warn = TTYColor::YELLOW @color_error = TTYColor::MAGENTA @color_fatal = TTYColor::RED @color_reset = TTYColor::NORMAL else @color_trace = '' @color_debug = '' @color_info = '' @color_warn = '' @color_error = '' @color_fatal = '' @color_reset = '' end self end
# File lib/fluent/log.rb, line 88 def enable_color? !@color_reset.empty? end
# File lib/fluent/log.rb, line 78 def enable_debug(b=true) @debug_mode = b self end
# File lib/fluent/log.rb, line 83 def enable_event(b=true) @self_event = b self end
# File lib/fluent/log.rb, line 197 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, @depth_offset, LEVEL_ERROR), msg, @color_reset].join rescue end
# File lib/fluent/log.rb, line 206 def error_backtrace(backtrace=$!.backtrace) dump_stacktrace(backtrace, LEVEL_ERROR) end
# File lib/fluent/log.rb, line 215 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, @depth_offset, LEVEL_FATAL), msg, @color_reset].join rescue end
# File lib/fluent/log.rb, line 224 def fatal_backtrace(backtrace=$!.backtrace) dump_stacktrace(backtrace, LEVEL_FATAL) end
# File lib/fluent/log.rb, line 161 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, @depth_offset, LEVEL_INFO), msg, @color_reset].join rescue end
# File lib/fluent/log.rb, line 170 def info_backtrace(backtrace=$!.backtrace) dump_stacktrace(backtrace, LEVEL_INFO) end
# File lib/fluent/log.rb, line 138 def on_debug(&block) return if @level > LEVEL_DEBUG block.call if block end
# File lib/fluent/log.rb, line 192 def on_error(&block) return if @level > LEVEL_ERROR block.call if block end
# File lib/fluent/log.rb, line 210 def on_fatal(&block) return if @level > LEVEL_FATAL block.call if block end
# File lib/fluent/log.rb, line 156 def on_info(&block) return if @level > LEVEL_INFO block.call if block end
# File lib/fluent/log.rb, line 119 def on_trace(&block) return if @level > LEVEL_TRACE block.call if block end
# File lib/fluent/log.rb, line 174 def on_warn(&block) return if @level > LEVEL_WARN block.call if block end
# File lib/fluent/log.rb, line 228 def puts(msg) @out.puts(msg) @out.flush msg rescue # FIXME nil end
# File lib/fluent/log.rb, line 124 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, @depth_offset, LEVEL_TRACE), msg, @color_reset].join rescue # logger should not raise an exception. This rescue prevents unexpected behaviour. end
# File lib/fluent/log.rb, line 134 def trace_backtrace(backtrace=$!.backtrace) dump_stacktrace(backtrace, LEVEL_TRACE) end
# File lib/fluent/log.rb, line 179 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, @depth_offset, LEVEL_WARN), msg, @color_reset].join rescue end
Generated with the Darkfish Rdoc Generator 2.