Class: Datadog::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/ddtrace/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

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Logger

Returns a new instance of Logger.



10
11
12
13
# File 'lib/ddtrace/logger.rb', line 10

def initialize(*args, &block)
  super
  self.progname = LOG_PREFIX
end

Instance Method Details

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ddtrace/logger.rb', line 15

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_given?
      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