Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow disabling of install messages #831

Merged
merged 5 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sdk/lib/opentelemetry/sdk/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Configurator # rubocop:disable Metrics/ClassLength

private_constant :USE_MODE_UNSPECIFIED, :USE_MODE_ONE, :USE_MODE_ALL

attr_writer :logger, :propagators, :error_handler, :id_generator
attr_writer :propagators, :error_handler, :id_generator

def initialize
@instrumentation_names = []
Expand All @@ -31,6 +31,10 @@ def logger
@logger ||= OpenTelemetry.logger
end

def logger=(new_logger)
@logger = ForwardingLogger.new(new_logger, level: ENV['OTEL_LOG_LEVEL'] || Logger::INFO)
end

def error_handler
@error_handler ||= OpenTelemetry.error_handler
end
Expand Down
61 changes: 61 additions & 0 deletions sdk/lib/opentelemetry/sdk/forwarding_logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require 'logger'

module OpenTelemetry
module SDK
class ForwardingLogger
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

def add(severity, message = nil, progname = nil)
return true if severity < @level
@logger.add(severity, message, progname)
end

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

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

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

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

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

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