Module: NewRelic::TelemetrySdk::Logger

Included in:
Buffer, Client, Harvester, Span
Defined in:
lib/newrelic/telemetry_sdk/logger.rb

Overview

The Logger Singleton object manages the logger for the SDK and is fully configurable by the user.

Any Ruby class that responds to the common methods of the Ruby standard Logger class can be configured for the SDk.

The logger may be configured like this:

Examples:

with configure block

require 'logger'

logger = ::Logger.new(STDOUT)
logger.level = Logger::WARN

NewRelic::TelemetrySdk.configure do |config|
  config.logger = logger
end

without configure block

require 'logger'

NewRelic::TelemetrySdk.logger = ::Logger.new("/dev/null")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.loggerObject



43
44
45
# File 'lib/newrelic/telemetry_sdk/logger.rb', line 43

def self.logger
  @logger ||= ::Logger.new(STDOUT)
end

.logger=(logger) ⇒ Object



39
40
41
# File 'lib/newrelic/telemetry_sdk/logger.rb', line 39

def self.logger= logger
  @logger = logger
end

Instance Method Details

#clear_already_loggedObject



56
57
58
59
60
# File 'lib/newrelic/telemetry_sdk/logger.rb', line 56

def clear_already_logged
  logger_mutex.synchronize do
    @already_logged = {}
  end
end

#log_error(message, exception = nil) ⇒ Object



62
63
64
65
# File 'lib/newrelic/telemetry_sdk/logger.rb', line 62

def log_error(message, exception = nil)
  logger.error message
  logger.error exception if exception
end

#log_once(level, key, *msgs) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/newrelic/telemetry_sdk/logger.rb', line 47

def log_once(level, key, *msgs)
  logger_mutex.synchronize do
    return if already_logged.include?(key)
    already_logged[key] = true
  end

  logger.send(level, *msgs)
end

#loggerObject



67
68
69
# File 'lib/newrelic/telemetry_sdk/logger.rb', line 67

def logger
  Logger.logger
end

#logger=(logger) ⇒ Object



71
72
73
# File 'lib/newrelic/telemetry_sdk/logger.rb', line 71

def logger= logger
  Logger.logger = logger
end