Class: Log4r::Logger::Repository
- Inherits:
-
Object
- Object
- Log4r::Logger::Repository
- Includes:
- Singleton
- Defined in:
- lib/log4r/repository.rb
Overview
The repository stores a Hash of loggers keyed to their fullnames and provides a few functions to reduce the code bloat in log4r/logger.rb. This class is supposed to be transparent to end users, hence it is a class within Logger. If anyone knows how to make this private, let me know.
Instance Attribute Summary collapse
-
#loggers ⇒ Object
readonly
Returns the value of attribute loggers.
Class Method Summary collapse
- .[](fullname) ⇒ Object
- .[]=(fullname, logger) ⇒ Object
-
.all_children(parent) ⇒ Object
Retrieves all children of a parent.
-
.find_ancestor(path) ⇒ Object
looks for the first defined logger in a child’s path or nil if none found (which will then be rootlogger).
-
.reassign_any_children(parent) ⇒ Object
when new loggers are introduced, they may get inserted into an existing inheritance tree.
Instance Method Summary collapse
-
#initialize ⇒ Repository
constructor
A new instance of Repository.
Constructor Details
#initialize ⇒ Repository
Returns a new instance of Repository.
29 30 31 |
# File 'lib/log4r/repository.rb', line 29 def initialize @loggers = Hash.new end |
Instance Attribute Details
#loggers ⇒ Object (readonly)
Returns the value of attribute loggers.
27 28 29 |
# File 'lib/log4r/repository.rb', line 27 def loggers @loggers end |
Class Method Details
.[](fullname) ⇒ Object
33 34 35 36 37 |
# File 'lib/log4r/repository.rb', line 33 def self.[](fullname) Thread.exclusive do instance.loggers[fullname] end # exclusive end |
.[]=(fullname, logger) ⇒ Object
39 40 41 42 43 |
# File 'lib/log4r/repository.rb', line 39 def self.[]=(fullname, logger) Thread.exclusive do instance.loggers[fullname] = logger end # exclusive end |
.all_children(parent) ⇒ Object
Retrieves all children of a parent
46 47 48 49 50 51 52 53 54 |
# File 'lib/log4r/repository.rb', line 46 def self.all_children(parent) # children have the parent name + delimiter in their fullname daddy = parent.name + Private::Config::LoggerPathDelimiter Thread.exclusive do for fullname, logger in instance.loggers yield logger if parent.is_root? || fullname =~ /#{daddy}/ end end # exclusive end |
.find_ancestor(path) ⇒ Object
looks for the first defined logger in a child’s path or nil if none found (which will then be rootlogger)
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/log4r/repository.rb', line 70 def self.find_ancestor(path) arr = path.split Log4rConfig::LoggerPathDelimiter logger = nil Thread.exclusive do while arr.size > 0 do logger = Repository[arr.join(Log4rConfig::LoggerPathDelimiter)] break unless logger.nil? arr.pop end end # exclusive logger end |
.reassign_any_children(parent) ⇒ Object
when new loggers are introduced, they may get inserted into an existing inheritance tree. this method updates the children of a logger to link their new parent
59 60 61 62 63 64 65 66 |
# File 'lib/log4r/repository.rb', line 59 def self.reassign_any_children(parent) Thread.exclusive do for fullname, logger in instance.loggers next if logger.is_root? logger.parent = parent if logger.path =~ /^#{parent.fullname}$/ end end # exclusive end |