Class: GrayLogger::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/gray_logger/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Proxy

Returns a new instance of Proxy.



5
6
7
8
# File 'lib/gray_logger/proxy.rb', line 5

def initialize(attributes={})
  self.proxied_logger = attributes[:proxied_logger]
  @gray_logger = attributes[:gray_logger]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)

delegate every method the proxy doesn’t know to gray_logger and proxied_logger. let them handle this.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gray_logger/proxy.rb', line 49

def method_missing(method_name, *args, &block)
  unless proxied_logger.nil?
    begin
      proxied_logger.send(method_name, *args, &block)
    rescue => e
      proxied_logger.error(e.backtrace.join("\n"))
    end
  else
    super
  end
end

Instance Attribute Details

#proxied_loggerObject

Returns the value of attribute proxied_logger.



3
4
5
# File 'lib/gray_logger/proxy.rb', line 3

def proxied_logger
  @proxied_logger
end

Instance Method Details

#gray_loggerObject



10
11
12
# File 'lib/gray_logger/proxy.rb', line 10

def gray_logger
  @gray_logger
end

#gray_logger?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/gray_logger/proxy.rb', line 14

def gray_logger?
  !!@gray_logger
end

#initialize_gray_logger!Object



18
19
20
# File 'lib/gray_logger/proxy.rb', line 18

def initialize_gray_logger!
  @gray_logger = ::GrayLogger::Logger.new(::GrayLogger.configuration)
end