Class: SemanticLogger::Formatters::Loki

Inherits:
Base
  • Object
show all
Defined in:
lib/semantic_logger/formatters/loki.rb

Constant Summary

Constants inherited from Base

Base::PRECISION

Instance Attribute Summary collapse

Attributes inherited from Base

#log, #log_application, #log_environment, #log_host, #logger, #precision, #time_format

Instance Method Summary collapse

Methods inherited from Base

build_time_format, #initialize, #pid

Constructor Details

This class inherits a constructor from SemanticLogger::Formatters::Base

Instance Attribute Details

#payload_valueObject

Returns the value of attribute payload_value.



6
7
8
# File 'lib/semantic_logger/formatters/loki.rb', line 6

def payload_value
  @payload_value
end

#streamObject

Returns the value of attribute stream.



6
7
8
# File 'lib/semantic_logger/formatters/loki.rb', line 6

def stream
  @stream
end

Instance Method Details

#batch(logs, logger) ⇒ Object

Returns [String] a JSON batch of logs



17
18
19
20
21
22
23
24
25
26
# File 'lib/semantic_logger/formatters/loki.rb', line 17

def batch(logs, logger)
  self.logger = logger

  streams = logs.map do |log|
    self.log = log
    build_stream
  end

  {streams: streams}.to_json
end

#call(log, logger) ⇒ Object

Returns [String] a single JSON log



9
10
11
12
13
14
# File 'lib/semantic_logger/formatters/loki.rb', line 9

def call(log, logger)
  self.logger = logger
  self.log = log

  {streams: [build_stream]}.to_json
end