Class: AppInsights::LoggerProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/appinsights/logger_proxy.rb

Constant Summary collapse

@@severity_levels =
{
  :debug => ApplicationInsights::Channel::Contracts::SeverityLevel::VERBOSE,
  :info => ApplicationInsights::Channel::Contracts::SeverityLevel::INFORMATION,
  :warn => ApplicationInsights::Channel::Contracts::SeverityLevel::WARNING,
  :error => ApplicationInsights::Channel::Contracts::SeverityLevel::ERROR,
  :fatal => ApplicationInsights::Channel::Contracts::SeverityLevel::CRITICAL,
  :unknown => ApplicationInsights::Channel::Contracts::SeverityLevel::CRITICAL,
}

Instance Method Summary collapse

Constructor Details

#initialize(logger, ignore_log_level = false, telemetry_client = nil) ⇒ LoggerProxy

Returns a new instance of LoggerProxy.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/appinsights/logger_proxy.rb', line 14

def initialize(logger, ignore_log_level=false, telemetry_client=nil)
  @logger = logger
  @ignore_log_level = ignore_log_level
  @telemetry_client = telemetry_client

  %w(debug info warn error fatal unknown).each do |level|
    LoggerProxy.class_eval do
      define_method level.to_sym do |*args , &block|
        if !@ignore_log_level && !logger.send("#{level}?".to_sym)
          return true
        end

        msg = message(*args, &block)
        tc = @telemetry_client || AppInsights::Context.telemetry_client
        tc.track_trace(msg, @@severity_levels[level.to_sym])
        @logger.send(level, msg, &block)
      end
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



37
38
39
# File 'lib/appinsights/logger_proxy.rb', line 37

def method_missing(name, *args, &block)
  @logger.send(name, *args, &block)
end