class EcsLogging::Logger
Constants
- RUBY_FORMAT
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/ecs_logging/logger.rb, line 26 def initialize(*args) super self.formatter = Formatter.new end
Public Instance Methods
add(severity, message = nil, progname = nil, include_origin: false, **extras) { || ... }
click to toggle source
# File lib/ecs_logging/logger.rb, line 31 def add(severity, message = nil, progname = nil, include_origin: false, **extras) severity ||= UNKNOWN return true if @logdev.nil? or severity < level progname = @progname if progname.nil? if message.nil? if block_given? message = yield else message = progname progname = @progname end end if apm_agent_present_and_running? extras[:"transaction.id"] = ElasticAPM.current_transaction&.id extras[:"trace.id"] = ElasticAPM.current_transaction&.trace_id extras[:"span.id"] = ElasticAPM.current_span&.id end @logdev.write( format_message( format_severity(severity), Time.now, progname, message, **extras ) ) true end
Private Instance Methods
apm_agent_present_and_running?()
click to toggle source
# File lib/ecs_logging/logger.rb, line 97 def apm_agent_present_and_running? return false unless defined?(::ElasticAPM) ElasticAPM.running? end
format_message(severity, datetime, progname, msg, **extras)
click to toggle source
# File lib/ecs_logging/logger.rb, line 93 def format_message(severity, datetime, progname, msg, **extras) formatter.call(severity, datetime, progname, msg, **extras) end
origin_from_caller(stack)
click to toggle source
# File lib/ecs_logging/logger.rb, line 81 def origin_from_caller(stack) return unless (ruby_match = stack.first.match(RUBY_FORMAT)) _, file, number, method = ruby_match.to_a { 'file.name': File.basename(file), 'file.line': number.to_i, function: method } end