Class: Datadog::Core::Logger

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

Overview

A custom logger with minor enhancements:

  • progname defaults to ddtrace to clearly identify Datadog dd-trace-rb related messages

  • adds last caller stack-trace info to know where the message comes from

Constant Summary collapse

PREFIX =

TODO: Consider renaming this to ‘datadog’

'ddtrace'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Logger

Returns a new instance of Logger.



13
14
15
16
17
# File 'lib/datadog/core/logger.rb', line 13

def initialize(*args, &block)
  super
  self.progname = PREFIX
  self.level = ::Logger::INFO
end

Instance Method Details

#add(severity, message = nil, progname = nil, &block) ⇒ Object Also known as: log



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/datadog/core/logger.rb', line 19

def add(severity, message = nil, progname = nil, &block)
  where = ''

  # We are in debug mode, or this is an error, add stack trace to help debugging
  if debug? || severity >= ::Logger::ERROR
    c = caller
    where = "(#{c[1]}) " if c.length > 1
  end

  if message.nil?
    if block
      super(severity, message, progname) do
        "[#{self.progname}] #{where}#{yield}"
      end
    else
      super(severity, message, "[#{self.progname}] #{where}#{progname}")
    end
  else
    super(severity, "[#{self.progname}] #{where}#{message}")
  end
end