Class: Hubbado::Log::Configuration

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.tags = tags
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



9
10
11
# File 'lib/hubbado/log/configuration.rb', line 9

def level
  @level
end

#loggersObject

Returns the value of attribute loggers.



8
9
10
# File 'lib/hubbado/log/configuration.rb', line 8

def loggers
  @loggers
end

#tagsObject

Returns the value of attribute tags.



10
11
12
# File 'lib/hubbado/log/configuration.rb', line 10

def tags
  @tags
end

Class Method Details

.instanceObject

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.

Yields:

  • (_self)

Yield Parameters:



30
31
32
33
34
# File 'lib/hubbado/log/configuration.rb', line 30

def change
  yield self

  @log_handlers = nil
end

#log_handlersObject

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