Class: Fluent::Logger::LevelFluentLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/fluent/logger/level_fluent_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_prefix = nil, *args) ⇒ LevelFluentLogger


28
29
30
31
32
33
34
35
36
37
# File 'lib/fluent/logger/level_fluent_logger.rb', line 28

def initialize(tag_prefix = nil, *args)
  @level = ::Logger::DEBUG
  @default_formatter = proc do |severity, datetime, progname, message|
    map = { level: severity }
    map[:message] = message if message
    map[:progname] = progname if progname
    map
  end
  @fluent_logger = FluentLogger.new(tag_prefix, *args)
end

Instance Method Details

#add(severity, message = nil, progname = nil, &block) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fluent/logger/level_fluent_logger.rb', line 39

def add(severity, message = nil, progname = nil, &block)
  severity ||= UNKNOWN
  if severity < @level
    return true
  end
  progname ||= @progname
  if message.nil?
    if block_given?
      message = yield
    else
      message = progname
      progname = @progname
    end
  end
  map = format_message(format_severity(severity), Time.now, progname, message)
  @fluent_logger.post(format_severity(severity).downcase, map)
  true
end

#closeObject


58
59
60
# File 'lib/fluent/logger/level_fluent_logger.rb', line 58

def close
  @fluent_logger.close
end

#connect?Boolean


68
69
70
# File 'lib/fluent/logger/level_fluent_logger.rb', line 68

def connect?
  @fluent_logger.connect?
end

#reopenObject


62
63
64
65
66
# File 'lib/fluent/logger/level_fluent_logger.rb', line 62

def reopen
  @fluent_logger.close
  # we do not call #connect! here because 1) FluentLogger#connect! is not a public method
  # 2) #post automatically connects if its connection is closed
end