Class: UU::LoggerFluent

Inherits:
Object
  • Object
show all
Defined in:
lib/uu/logger_fluent.rb

Defined Under Namespace

Classes: Formatter, Nil

Constant Summary collapse

NIL =
Nil.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cxt, host: , port: ) ⇒ LoggerFluent

Returns a new instance of LoggerFluent.



59
60
61
62
# File 'lib/uu/logger_fluent.rb', line 59

def initialize(cxt, host: ENV['FLUENTD_HOST'], port: ENV['FLUENTD_PORT'])
  @logger = create_logger(host, port)
  @formatter = Formatter.new(cxt)
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



75
76
77
# File 'lib/uu/logger_fluent.rb', line 75

def formatter
  @formatter
end

#loggerObject (readonly)

Returns the value of attribute logger.



74
75
76
# File 'lib/uu/logger_fluent.rb', line 74

def logger
  @logger
end

Instance Method Details

#create_logger(host, port) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/uu/logger_fluent.rb', line 64

def create_logger(host, port)
  return NIL unless host

  Fluent::Logger::FluentLogger.new(
    nil,
    nanosecond_precision: true,
    host: host, **(port ? { port: port.to_i } : {})
  )
end

#format_message(severity, message) ⇒ Object



77
78
79
# File 'lib/uu/logger_fluent.rb', line 77

def format_message(severity, message)
  @formatter.call(severity, message)
end