Class: Hubbado::Log::Configuration
- Inherits:
-
Object
- Object
- Hubbado::Log::Configuration
- Defined in:
- lib/hubbado/log/configuration.rb
Constant Summary collapse
- DEFAULT_LEVEL =
Tracing is off until somebody asks for it, which is what lets a debug message be written for a human watching one run without it also reaching every unattended log.
:info
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#loggers ⇒ Object
Returns the value of attribute loggers.
-
#tags ⇒ Object
Returns the value of attribute tags.
Class Method Summary collapse
-
.instance ⇒ Object
The configuration is the process's rather than a class's, so a subclass of Log reads the one a command wrote and there is a single set of handlers to build from it.
Instance Method Summary collapse
-
#change {|_self| ... } ⇒ Object
Whatever the block leaves behind is what the process is configured for, and the handlers are built again from it.
-
#initialize(level: nil, tags: nil) ⇒ Configuration
constructor
A new instance of Configuration.
-
#log_handlers ⇒ Object
The handlers themselves, one set for the process.
Constructor Details
#initialize(level: nil, tags: nil) ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 24 25 |
# File 'lib/hubbado/log/configuration.rb', line 21 def initialize(level: nil, tags: nil) self.loggers = [] self.level = level || DEFAULT_LEVEL self. = end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
9 10 11 |
# File 'lib/hubbado/log/configuration.rb', line 9 def level @level end |
#loggers ⇒ Object
Returns the value of attribute loggers.
8 9 10 |
# File 'lib/hubbado/log/configuration.rb', line 8 def loggers @loggers end |
#tags ⇒ Object
Returns the value of attribute tags.
10 11 12 |
# File 'lib/hubbado/log/configuration.rb', line 10 def @tags end |
Class Method Details
.instance ⇒ Object
The configuration is the process's rather than a class's, so a subclass of Log reads the one a command wrote and there is a single set of handlers to build from it.
The one place the environment is read. A command names its level and tags here or not at all, and everything downstream is handed the value rather than the variable.
17 18 19 |
# File 'lib/hubbado/log/configuration.rb', line 17 def self.instance @instance ||= new(level: ENV[LEVEL_VARIABLE], tags: ENV[TAGS_VARIABLE]) end |
Instance Method Details
#change {|_self| ... } ⇒ Object
Whatever the block leaves behind is what the process is configured for, and the handlers are built again from it. Named here rather than left to the caller, because a block is free to mutate the list of loggers in place and never reach the writer below.
30 31 32 33 34 |
# File 'lib/hubbado/log/configuration.rb', line 30 def change yield self @log_handlers = nil end |
#log_handlers ⇒ Object
The handlers themselves, one set for the process. A handler holds what it has been told, so a second set built somewhere else would be a second place to read it back from.
38 39 40 |
# File 'lib/hubbado/log/configuration.rb', line 38 def log_handlers @log_handlers ||= loggers.map(&:new) end |