Skip to content

Commit

Permalink
Merge pull request #1158 from DataDog/fix/logger_recursion
Browse files Browse the repository at this point in the history
Prevent logger recursion during startup
  • Loading branch information
delner authored Aug 31, 2020
2 parents 3bb7f74 + 8c41cb7 commit e98ca74
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/ddtrace/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,25 @@ def configure(target = configuration, opts = {})
def_delegators \
:components,
:health_metrics,
:logger,
:runtime_metrics,
:tracer

def logger
if instance_variable_defined?(:@components) && @components
@temp_logger = nil
components.logger
else
# Use default logger without initializing components.
# This prevents recursive loops while initializing.
# e.g. Get logger --> Build components --> Log message --> Repeat...
@temp_logger ||= begin
logger = configuration.logger.instance || Datadog::Logger.new(STDOUT)
logger.level = configuration.diagnostics.debug ? ::Logger::DEBUG : configuration.logger.level
logger
end
end
end

def shutdown!
components.shutdown! if instance_variable_defined?(:@components) && @components
end
Expand Down

0 comments on commit e98ca74

Please sign in to comment.