Class: OpenTelemetry::SDK::ForwardingLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/sdk/forwarding_logger.rb

Overview

The ForwardingLogger provides a wrapper to control the OpenTelemetry log level, while respecting the configured level of the supplied logger. If the OTEL_LOG_LEVEL is set to debug, and the supplied logger is configured with an ERROR log level, only OpenTelemetry logs at the ERROR level or higher will be emitted.

Instance Method Summary collapse

Constructor Details

#initialize(logger, level:) ⇒ ForwardingLogger

Returns a new instance of ForwardingLogger.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/opentelemetry/sdk/forwarding_logger.rb', line 13

def initialize(logger, level:)
  @logger = logger

  if level.is_a?(Integer)
    @level = level
  else
    case level.to_s.downcase
    when 'debug'
      @level = Logger::DEBUG
    when 'info'
      @level = Logger::INFO
    when 'warn'
      @level = Logger::WARN
    when 'error'
      @level = Logger::ERROR
    when 'fatal'
      @level = Logger::FATAL
    when 'unknown'
      @level = Logger::UNKNOWN
    else
      raise ArgumentError, "invalid log level: #{level}"
    end
  end
end

Instance Method Details

#add(severity, message = nil, progname = nil, &block) ⇒ Object



38
39
40
41
42
# File 'lib/opentelemetry/sdk/forwarding_logger.rb', line 38

def add(severity, message = nil, progname = nil, &block)
  return true if severity < @level

  @logger.add(severity, message, progname, &block)
end

#debug(progname = nil, &block) ⇒ Object



44
45
46
# File 'lib/opentelemetry/sdk/forwarding_logger.rb', line 44

def debug(progname = nil, &block)
  add(Logger::DEBUG, nil, progname, &block)
end

#error(progname = nil, &block) ⇒ Object



56
57
58
# File 'lib/opentelemetry/sdk/forwarding_logger.rb', line 56

def error(progname = nil, &block)
  add(Logger::ERROR, nil, progname, &block)
end

#fatal(progname = nil, &block) ⇒ Object



60
61
62
# File 'lib/opentelemetry/sdk/forwarding_logger.rb', line 60

def fatal(progname = nil, &block)
  add(Logger::FATAL, nil, progname, &block)
end

#info(progname = nil, &block) ⇒ Object



48
49
50
# File 'lib/opentelemetry/sdk/forwarding_logger.rb', line 48

def info(progname = nil, &block)
  add(Logger::INFO, nil, progname, &block)
end

#unknown(progname = nil, &block) ⇒ Object



64
65
66
# File 'lib/opentelemetry/sdk/forwarding_logger.rb', line 64

def unknown(progname = nil, &block)
  add(Logger::UNKNOWN, nil, progname, &block)
end

#warn(progname = nil, &block) ⇒ Object



52
53
54
# File 'lib/opentelemetry/sdk/forwarding_logger.rb', line 52

def warn(progname = nil, &block)
  add(Logger::WARN, nil, progname, &block)
end