Class: Loggr::Adapter::AbstractAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/loggr/adapter/abstract.rb

Overview

A basically abstract base class for logger backend implementations, provides a default implementation for MDC (hash & thread local based).

Ensure to implement ‘#logger`.

Direct Known Subclasses

BaseAdapter, NOPAdapter, RailsAdapter

Instance Method Summary collapse

Instance Method Details

#logger(name, options = {}) ⇒ Object

Implement which creates a new instance of a logger.



12
13
14
# File 'lib/loggr/adapter/abstract.rb', line 12

def logger(name, options = {})
  raise "#{self.class.name}#logger is declared `abstract': implement #logger method"
end

#mdcObject

Use a simple thread local hash as fake MDC, because it’s not supported by the logger anyway - but it should be available for consistency and usage.



19
20
21
22
# File 'lib/loggr/adapter/abstract.rb', line 19

def mdc
  mdc_key = "#{self.class.name}.mdc"
  Thread.current[mdc_key] ||= Hash.new
end