class ElasticLogger::ElkWriter
Attributes
config[R]
name[R]
Public Class Methods
new(name:, config:)
click to toggle source
# File lib/elastic-logger/elk_writer.rb, line 5 def initialize(name:, config:) @config = config @name = name end
Public Instance Methods
log(severity, hash)
click to toggle source
# File lib/elastic-logger/elk_writer.rb, line 10 def log(severity, hash) client.index(index: index, type: name, body: build_log(severity, hash)) end
Private Instance Methods
build_log(severity, hash)
click to toggle source
# File lib/elastic-logger/elk_writer.rb, line 17 def build_log(severity, hash) { "@fields" => hash, "@timestamp" => timestamp.iso8601(3), "@severity" => severity.to_s.upcase } end
client()
click to toggle source
# File lib/elastic-logger/elk_writer.rb, line 25 def client @client ||= Elasticsearch::Client.new(host: config.host) end
index()
click to toggle source
# File lib/elastic-logger/elk_writer.rb, line 29 def index "#{name}-#{timestamp.strftime('%Y.%m.%d')}" end
timestamp()
click to toggle source
# File lib/elastic-logger/elk_writer.rb, line 33 def timestamp Time.now.utc end