Class: LogTagger

Inherits:
Object
  • Object
show all
Defined in:
lib/ucb_rails/log_tagger.rb

Overview

Wraps another logger and tags output.

Constant Summary collapse

LOGGER_METHODS =
[:debug, :error, :fatal, :info, :unknown, :warn]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, logger) ⇒ LogTagger

Returns a new instance of LogTagger.



7
8
9
10
# File 'lib/ucb_rails/log_tagger.rb', line 7

def initialize(tag, logger)
  self.tag = tag
  self.logger = logger
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/ucb_rails/log_tagger.rb', line 12

def method_missing(method, *args)
  if LOGGER_METHODS.include?(method)
    logger.send(method, "[#{tag}] #{args.first}")
  else
    super
  end
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/ucb_rails/log_tagger.rb', line 5

def logger
  @logger
end

#tagObject

Returns the value of attribute tag.



5
6
7
# File 'lib/ucb_rails/log_tagger.rb', line 5

def tag
  @tag
end