Class: BBK::Utils::ProxyLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/bbk/utils/proxy_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, tags:) ⇒ ProxyLogger

Returns a new instance of ProxyLogger.



11
12
13
14
15
# File 'lib/bbk/utils/proxy_logger.rb', line 11

def initialize(logger, tags:)
  @logger = logger
  @tagged = @logger.respond_to?(:tagged)
  @tags = [tags].flatten
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



22
23
24
25
26
27
28
29
30
31
# File 'lib/bbk/utils/proxy_logger.rb', line 22

def method_missing(method, *args, &block)
  super unless logger.respond_to?(method)

  if @tagged
    current_tags = tags - logger.formatter.current_tags
    logger.tagged(current_tags) { logger.send(method, *args, &block) }
  else
    logger.send(method, *args, &block)
  end
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/bbk/utils/proxy_logger.rb', line 9

def logger
  @logger
end

#tagsObject (readonly)

Returns the value of attribute tags.



9
10
11
# File 'lib/bbk/utils/proxy_logger.rb', line 9

def tags
  @tags
end

Instance Method Details

#add_tags(*tags) ⇒ Object



17
18
19
20
# File 'lib/bbk/utils/proxy_logger.rb', line 17

def add_tags(*tags)
  @tags += tags.flatten
  @tags = @tags.uniq
end

#respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bbk/utils/proxy_logger.rb', line 33

def respond_to?(name, include_private=false)
  logger.send(:respond_to?, name, include_private) || super
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bbk/utils/proxy_logger.rb', line 37

def respond_to_missing?(method_name, include_private = false)
  logger.send(:respond_to_missing?, method_name, include_private) || super
end