Class: Patriot::Util::Logger::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/patriot/util/logger/factory.rb

Overview

logger factory

Direct Known Subclasses

Log4rFactory, WebrickLogFactory

Constant Summary collapse

FACTORY_CLASS_KEY =

configuration key for logger factory class

:log_factory
DEFAULT_LOGGER_FACTORY_CLASS =

default logger factory class

'Patriot::Util::Logger::Log4rFactory'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFactory

Returns a new instance of Factory.



30
31
32
33
# File 'lib/patriot/util/logger/factory.rb', line 30

def initialize
  @mutex   = Mutex.new
  @loggers = {}
end

Class Method Details

.create_logger(name, config) ⇒ Patriot::Util::Logger::Facade

Parameters:

Returns:



17
18
19
20
21
22
# File 'lib/patriot/util/logger/factory.rb', line 17

def self.create_logger(name, config)
  klass = get_factory_class_name(config)
  # implentations of logger facotory should include Singleton
  logger = eval(klass).instance.get_logger(name, config)
  return logger
end

.get_factory_class_name(config) ⇒ String

Returns factory class name.

Parameters:

Returns:

  • (String)

    factory class name



26
27
28
# File 'lib/patriot/util/logger/factory.rb', line 26

def self.get_factory_class_name(config)
  return config.get(FACTORY_CLASS_KEY, DEFAULT_LOGGER_FACTORY_CLASS).to_s
end

Instance Method Details

#build(name, config) ⇒ Object

build logger should be overridden in sub-classes

Parameters:

Raises:

  • (NotImplementedError)


52
53
54
# File 'lib/patriot/util/logger/factory.rb', line 52

def build(name, config)
  raise NotImplementedError
end

#get_logger(name, config) ⇒ Patriot::Util::Logger::Facade

Parameters:

Returns:



38
39
40
41
42
43
44
45
46
# File 'lib/patriot/util/logger/factory.rb', line 38

def get_logger(name, config)
  @mutex.synchronize do
    unless @loggers.has_key?(name)
      logger = build(name,config)
      @loggers[name] = Facade.new(logger)
    end
    return @loggers[name]
  end
end