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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LoggerFluent.



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/uu/logger_fluent.rb', line 67

def initialize(cxt, host: ENV['FLUENTD_HOST'], port: ENV['FLUENTD_PORT'])
  @logger =
    if host
      self.class.cached_logger[
        { host: host, **(port ? { port: port.to_i } : {}) }
      ]
    else
      NIL
    end
  @formatter = Formatter.new(cxt, 'tag')
end

Class Attribute Details

.cached_loggerObject (readonly)

Returns the value of attribute cached_logger.



64
65
66
# File 'lib/uu/logger_fluent.rb', line 64

def cached_logger
  @cached_logger
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



80
81
82
# File 'lib/uu/logger_fluent.rb', line 80

def formatter
  @formatter
end

#loggerObject (readonly)

Returns the value of attribute logger.



79
80
81
# File 'lib/uu/logger_fluent.rb', line 79

def logger
  @logger
end

Instance Method Details

#format_message(severity, message) ⇒ Object



82
83
84
# File 'lib/uu/logger_fluent.rb', line 82

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