Class: Entitlements::Auditor::Base::CustomLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/entitlements/auditor/base.rb

Overview

Set up a logger class that wraps incoming messages with the prefix and (if meaningful) the provider ID. Messages are then sent with the requested priority to the actual logger object.

Instance Method Summary collapse

Constructor Details

#initialize(underlying_object, underlying_logger) ⇒ CustomLogger

Returns a new instance of CustomLogger.



63
64
65
66
# File 'lib/entitlements/auditor/base.rb', line 63

def initialize(underlying_object, underlying_logger)
  @underlying_object = underlying_object
  @underlying_logger = underlying_logger
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



78
79
80
81
# File 'lib/entitlements/auditor/base.rb', line 78

def method_missing(m, *args, &block)
  args[0] = "#{prefix}: #{args.first}"
  @underlying_logger.send(m, *args, &block)
end

Instance Method Details

#prefixObject



68
69
70
71
72
73
74
75
76
# File 'lib/entitlements/auditor/base.rb', line 68

def prefix
  @prefix ||= begin
    if @underlying_object.provider_id == @underlying_object.class.to_s.split("::").last
      @underlying_object.class.to_s
    else
      "#{@underlying_object.class}[#{@underlying_object.provider_id}]"
    end
  end
end