class ElasticLogger::DiskWriter
Attributes
config[R]
name[R]
Public Class Methods
new(name:, config:)
click to toggle source
# File lib/elastic-logger/disk_writer.rb, line 3 def initialize(name:, config:) @config = config @name = name end
Public Instance Methods
log(severity, hash)
click to toggle source
# File lib/elastic-logger/disk_writer.rb, line 8 def log(severity, hash) logger.send(severity, build_log(hash)) end
Private Instance Methods
build_log(hash)
click to toggle source
# File lib/elastic-logger/disk_writer.rb, line 15 def build_log(hash) hash.merge("@timestamp" => timestamp.iso8601(3)) end
logger()
click to toggle source
# File lib/elastic-logger/disk_writer.rb, line 19 def logger @logger ||= ::Logger.new(path_with(name), 'monthly').tap { |lgger| lgger.formatter = lambda { |_, _, _, msg| msg.to_h.to_json + "\n" } } end
path_with(name)
click to toggle source
# File lib/elastic-logger/disk_writer.rb, line 25 def path_with(name) Pathname.new(config.path).join("#{name}.log") end
timestamp()
click to toggle source
# File lib/elastic-logger/disk_writer.rb, line 29 def timestamp Time.now.utc end