Class: TaggedLogger::ClassSpecificLogger

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

Overview

class methods

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ ClassSpecificLogger

Returns a new instance of ClassSpecificLogger.



190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/tagged_logger/tagged_logger.rb', line 190

def initialize(klass)
  @klass = klass
  [:debug, :warn, :info, :error, :fatal].each do |level|
    blocks = TaggedLogger.blocks_for(level, klass)
    eigenclass.send(:define_method, level) do |msg|
      blocks.each { |(tag_alias, block)| block.call(level, tag_alias, msg) }
    end
    eigenclass.send(:define_method, "#{level}?".to_sym) do
      !blocks.empty?
    end
  end    
end

Instance Method Details

#detachObject



203
204
205
206
207
# File 'lib/tagged_logger/tagged_logger.rb', line 203

def detach
  @klass.class_eval do
    @class_logger = nil
  end
end

#eigenclassObject



186
187
188
# File 'lib/tagged_logger/tagged_logger.rb', line 186

def eigenclass
  class <<self; self; end
end