Class: LogStashLogger::Formatter::Base

Inherits:
Logger::Formatter
  • Object
show all
Includes:
TaggedLogging::Formatter
Defined in:
lib/logstash-logger/formatter/base.rb

Direct Known Subclasses

Cee, Json, JsonLines, LogStashEvent

Constant Summary collapse

FAILED_TO_FORMAT_MSG =
'Failed to format log event'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TaggedLogging::Formatter

#clear_tags!, #current_tags, #pop_tags, #push_tags, #tagged

Constructor Details

#initialize(customize_event: nil, error_logger: LogStashLogger.configuration.default_error_logger) ⇒ Base

Returns a new instance of Base.



17
18
19
20
21
# File 'lib/logstash-logger/formatter/base.rb', line 17

def initialize(customize_event: nil, error_logger: LogStashLogger.configuration.default_error_logger)
  @customize_event = customize_event
  @error_logger = error_logger
  super()
end

Instance Attribute Details

#error_logger ⇒ Object

Returns the value of attribute error_logger.



14
15
16
# File 'lib/logstash-logger/formatter/base.rb', line 14

def error_logger
  @error_logger
end

Instance Method Details

#call(severity, time, _progname, message) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/logstash-logger/formatter/base.rb', line 23

def call(severity, time, _progname, message)
  event = build_event(message, severity, time)
  format_event(event) unless event.cancelled?
rescue StandardError => e
  log_error(e)
  FAILED_TO_FORMAT_MSG
end