Class: EcsLogging::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/ecs_logging/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Logger

Returns a new instance of Logger.



26
27
28
29
# File 'lib/ecs_logging/logger.rb', line 26

def initialize(*args)
  super
  self.formatter = Formatter.new
end

Instance Method Details

#add(severity, message = nil, progname = nil, include_origin: false, **extras) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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