Class: Datadog::DI::Logger Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/di/logger.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Logger facade to add the trace method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings, target) ⇒ Logger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the logger facade with the trace-logging gate resolved once. Resolving the gate at construction keeps the per-call settings traversal off the probe hot path. Components are rebuilt on reconfiguration, so the cached value tracks configuration changes.

Parameters:



18
19
20
21
# File 'lib/datadog/di/logger.rb', line 18

def initialize(settings, target)
  @trace_logging = settings.dynamic_instrumentation.internal.trace_logging
  @target = target
end

Instance Attribute Details

#target ⇒ ::Logger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The target logger.

Returns:

  • (::Logger)


28
29
30
# File 'lib/datadog/di/logger.rb', line 28

def target
  @target
end

#trace_logging ⇒ Boolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether trace logging is enabled.

Returns:

  • (Boolean)


25
26
27
# File 'lib/datadog/di/logger.rb', line 25

def trace_logging
  @trace_logging
end

Instance Method Details

#debug(message = nil, &block) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Writes the given message or the block's message to the target logger.

Parameters:

  • message (String, nil) (defaults to: nil) —

    message written when no block is given



35
36
37
38
# File 'lib/datadog/di/logger.rb', line 35

def debug(message = nil, &block)
  target.debug(message, &block)
  nil
end

#trace ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Writes the block's message to the target logger at debug level when the trace-logging gate resolved at construction is enabled.



44
45
46
47
48
49
# File 'lib/datadog/di/logger.rb', line 44

def trace
  if trace_logging
    debug { yield }
  end
  nil
end