Parent

Namespace

Class/Module Index [+]

Quicksearch

Fluent::Log

Attributes

level[RW]
out[RW]
tag[RW]
time_format[RW]

Public Class Methods

new(out=STDERR, level=LEVEL_TRACE) click to toggle source
# File lib/fluent/log.rb, line 45
def initialize(out=STDERR, level=LEVEL_TRACE)
  @out = out
  @level = level
  @debug_mode = false
  @self_event = false
  @tag = 'fluent'
  @time_format = '%Y-%m-%d %H:%M:%S %z '
  enable_color out.tty?
end

Public Instance Methods

DEBUG(*args, &block) click to toggle source
Alias for: debug
ERROR(*args, &block) click to toggle source
Alias for: error
FATAL(*args, &block) click to toggle source
Alias for: fatal
INFO(*args, &block) click to toggle source
Alias for: info
TRACE(*args, &block) click to toggle source
Alias for: trace
WARN(*args, &block) click to toggle source
Alias for: warn
debug(*args, &block) click to toggle source
# File lib/fluent/log.rb, line 118
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
end
Also aliased as: DEBUG
debug_backtrace(backtrace=$!.backtrace) click to toggle source
# File lib/fluent/log.rb, line 126
def debug_backtrace(backtrace=$!.backtrace)
  return if @level > LEVEL_DEBUG
  time = Time.now
  backtrace.each {|msg|
    puts ["  ", caller_line(time, 4, LEVEL_DEBUG), msg].join
  }
  nil
end
enable_color(b=true) click to toggle source
# File lib/fluent/log.rb, line 70
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
enable_debug(b=true) click to toggle source
# File lib/fluent/log.rb, line 60
def enable_debug(b=true)
  @debug_mode = b
  self
end
enable_event(b=true) click to toggle source
# File lib/fluent/log.rb, line 65
def enable_event(b=true)
  @self_event = b
  self
end
error(*args, &block) click to toggle source
# File lib/fluent/log.rb, line 184
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
end
Also aliased as: ERROR
error_backtrace(backtrace=$!.backtrace) click to toggle source
# File lib/fluent/log.rb, line 192
def error_backtrace(backtrace=$!.backtrace)
  return if @level > LEVEL_ERROR
  time = Time.now
  backtrace.each {|msg|
    puts ["  ", caller_line(time, 4, LEVEL_ERROR), msg].join
  }
  nil
end
fatal(*args, &block) click to toggle source
# File lib/fluent/log.rb, line 206
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
end
Also aliased as: FATAL
fatal_backtrace(backtrace=$!.backtrace) click to toggle source
# File lib/fluent/log.rb, line 214
def fatal_backtrace(backtrace=$!.backtrace)
  return if @level > LEVEL_FATAL
  time = Time.now
  backtrace.each {|msg|
    puts ["  ", caller_line(time, 4, LEVEL_FATAL), msg].join
  }
  nil
end
flush() click to toggle source
# File lib/fluent/log.rb, line 236
def flush
  @out.flush
end
info(*args, &block) click to toggle source
# File lib/fluent/log.rb, line 140
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
end
Also aliased as: INFO
info_backtrace(backtrace=$!.backtrace) click to toggle source
# File lib/fluent/log.rb, line 148
def info_backtrace(backtrace=$!.backtrace)
  return if @level > LEVEL_INFO
  time = Time.now
  backtrace.each {|msg|
    puts ["  ", caller_line(time, 4, LEVEL_INFO), msg].join
  }
  nil
end
on_debug(&block) click to toggle source
# File lib/fluent/log.rb, line 113
def on_debug(&block)
  return if @level > LEVEL_DEBUG
  block.call if block
end
on_error(&block) click to toggle source
# File lib/fluent/log.rb, line 179
def on_error(&block)
  return if @level > LEVEL_ERROR
  block.call if block
end
on_fatal(&block) click to toggle source
# File lib/fluent/log.rb, line 201
def on_fatal(&block)
  return if @level > LEVEL_FATAL
  block.call if block
end
on_info(&block) click to toggle source
# File lib/fluent/log.rb, line 135
def on_info(&block)
  return if @level > LEVEL_INFO
  block.call if block
end
on_trace(&block) click to toggle source
# File lib/fluent/log.rb, line 91
def on_trace(&block)
  return if @level > LEVEL_TRACE
  block.call if block
end
on_warn(&block) click to toggle source
# File lib/fluent/log.rb, line 157
def on_warn(&block)
  return if @level > LEVEL_WARN
  block.call if block
end
puts(msg) click to toggle source
# File lib/fluent/log.rb, line 223
def puts(msg)
  @out.puts(msg)
  @out.flush
  msg
rescue
  # FIXME
  nil
end
trace(*args, &block) click to toggle source
# File lib/fluent/log.rb, line 96
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
end
Also aliased as: TRACE
trace_backtrace(backtrace=$!.backtrace) click to toggle source
# File lib/fluent/log.rb, line 104
def trace_backtrace(backtrace=$!.backtrace)
  return if @level > LEVEL_TRACE
  time = Time.now
  backtrace.each {|msg|
    puts ["  ", caller_line(time, 4, LEVEL_TRACE), msg].join
  }
  nil
end
warn(*args, &block) click to toggle source
# File lib/fluent/log.rb, line 162
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
end
Also aliased as: WARN
warn_backtrace(backtrace=$!.backtrace) click to toggle source
# File lib/fluent/log.rb, line 170
def warn_backtrace(backtrace=$!.backtrace)
  return if @level > LEVEL_WARN
  time = Time.now
  backtrace.each {|msg|
    puts ["  ", caller_line(time, 4, LEVEL_WARN), msg].join
  }
  nil
end
write(data) click to toggle source
# File lib/fluent/log.rb, line 232
def write(data)
  @out.write(data)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.