Class: BBK::App::ProxyLogger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, tags:) ⇒ ProxyLogger

Returns a new instance of ProxyLogger.



9
10
11
12
13
# File 'lib/bbk/app/proxy_logger.rb', line 9

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



20
21
22
23
24
25
26
27
28
29
# File 'lib/bbk/app/proxy_logger.rb', line 20

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.



7
8
9
# File 'lib/bbk/app/proxy_logger.rb', line 7

def logger
  @logger
end

#tagsObject (readonly)

Returns the value of attribute tags.



7
8
9
# File 'lib/bbk/app/proxy_logger.rb', line 7

def tags
  @tags
end

Instance Method Details

#add_tags(*tags) ⇒ Object



15
16
17
18
# File 'lib/bbk/app/proxy_logger.rb', line 15

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

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/bbk/app/proxy_logger.rb', line 31

def respond_to?(*args)
  logger.send(:respond_to?, *args) || super
end

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

Returns:

  • (Boolean)


35
36
37
# File 'lib/bbk/app/proxy_logger.rb', line 35

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