Class: SemanticLogger::Formatters::Fluentd

Inherits:
Json
  • Object
show all
Defined in:
lib/semantic_logger/formatters/fluentd.rb

Overview

Fluentd is similar to SemanticLogger::Formatters::Json but with log levels that are recognized by kubernetes fluentd.

Instance Attribute Summary collapse

Attributes inherited from Raw

#hash, #time_key

Attributes inherited from Base

#filter, #instance_named_tags, #instance_tags, #name

Instance Method Summary collapse

Methods inherited from Json

#batch, #call

Methods inherited from Raw

#application, #call, #duration, #environment, #exception, #host, #message, #metric, #name, #named_tags, #payload, #tags, #time

Methods inherited from Base

#backtrace, #fast_tag, #level=, #log, #measure, #named_tags, #pop_tags, #push_tags, #should_log?, #silence, #tagged, #tags, #with_level

Constructor Details

#initialize(time_format: :rfc_3339, time_key: :time, need_process_info: false, log_host: false, **args) ⇒ Fluentd

Returns a new instance of Fluentd.



10
11
12
13
# File 'lib/semantic_logger/formatters/fluentd.rb', line 10

def initialize(time_format: :rfc_3339, time_key: :time, need_process_info: false, log_host: false, **args)
  @need_process_info = need_process_info
  super(time_format: time_format, time_key: time_key, log_host: log_host, **args)
end

Instance Attribute Details

#need_process_infoObject (readonly)

Returns the value of attribute need_process_info.



8
9
10
# File 'lib/semantic_logger/formatters/fluentd.rb', line 8

def need_process_info
  @need_process_info
end

Instance Method Details

#file_name_and_lineObject



32
33
34
# File 'lib/semantic_logger/formatters/fluentd.rb', line 32

def file_name_and_line
  super if need_process_info
end

#levelObject



15
16
17
18
# File 'lib/semantic_logger/formatters/fluentd.rb', line 15

def level
  hash["severity"]       = log.level
  hash["severity_index"] = log.level_index
end

#pidObject

Ignore process fields: pid, thread, file and line by default. These are rarely useful under Fluentd (e.g. containerized processes usually have pid 1), so they are only included when explicitly requested via need_process_info: true.



24
25
26
# File 'lib/semantic_logger/formatters/fluentd.rb', line 24

def pid
  super if need_process_info
end

#thread_nameObject



28
29
30
# File 'lib/semantic_logger/formatters/fluentd.rb', line 28

def thread_name
  super if need_process_info
end