Class: Taglog

Inherits:
Module
  • Object
show all
Defined in:
lib/taglog.rb,
lib/taglog/version.rb

Overview

Wrap a class that has ‘#logger` method to insert tag without over defining actual logger’s methods.

Defined Under Namespace

Classes: Proxy

Constant Summary collapse

LEVELS =
Logger::Severity.constants.map(&:downcase)
VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(tag) ⇒ Taglog

Returns a new instance of Taglog.



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

def initialize(tag)
  @tag = tag
end

Instance Method Details

#extended(base) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/taglog.rb', line 14

def extended(base)
  tag = @tag
  base.class_eval do
    define_method(:logger_with_tag) do
      Proxy.new(self, tag)
    end
    alias_method :logger_without_tag, :logger
    alias_method :logger, :logger_with_tag
  end
end