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 level that are recongnized by kubernetes fluentd.

Instance Attribute Summary collapse

Attributes inherited from Raw

#hash, #log, #logger, #time_key

Attributes inherited from Base

#filter, #name

Instance Method Summary collapse

Methods inherited from Raw

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

Methods inherited from Base

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

Constructor Details

#initialize(log_host: true, log_application: true, need_process_info: false) ⇒ Fluentd

Returns a new instance of Fluentd.



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

def initialize(log_host: true, log_application: true, need_process_info: false)
  @need_process_info = need_process_info
  super(log_host: log_host, log_application: log_application, time_key: 'time', time_format: :rfc_3339)
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

#call(log, logger) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/semantic_logger/formatters/fluentd.rb', line 25

def call(log, logger)
  self.hash   = {}
  self.log    = log
  self.logger = logger

  host; application; time; severity; process_info; duration; tags; named_tags; name; message; payload; exception; metric
  hash

  hash.to_json
end

#process_infoObject



20
21
22
23
# File 'lib/semantic_logger/formatters/fluentd.rb', line 20

def process_info
  # Ignore fields: pid, thread, file and line by default
  super() if need_process_info
end

#severityObject



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

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