Class: Patriot::Util::Logger::Factory
- Inherits:
-
Object
- Object
- Patriot::Util::Logger::Factory
- Defined in:
- lib/patriot/util/logger/factory.rb
Overview
logger factory
Direct Known Subclasses
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
- .create_logger(name, config) ⇒ Patriot::Util::Logger::Facade
-
.get_factory_class_name(config) ⇒ String
Factory class name.
Instance Method Summary collapse
-
#build(name, config) ⇒ Object
build logger should be overridden in sub-classes.
- #get_logger(name, config) ⇒ Patriot::Util::Logger::Facade
-
#initialize ⇒ Factory
constructor
A new instance of Factory.
Constructor Details
#initialize ⇒ Factory
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
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.
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
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
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 |