Module: Automatic::Log

Defined in:
lib/automatic/log.rb

Constant Summary collapse

LOG_LEVELS =

In increasing order of severity. 'none' is the threshold that admits nothing; it is never used as the level of a message.

%w[info warn error none].freeze
DEFAULT_LEVEL =
'info'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject



32
33
34
# File 'lib/automatic/log.rb', line 32

def logger
  @logger ||= Logger.new($stdout)
end

Class Method Details

.level(level = nil) ⇒ Object

Set the threshold. An unrecognised name, including nil, means the default: an unattended run should not be silenced by a typo in a Recipe, nor should it raise in the middle of a job.



28
29
30
# File 'lib/automatic/log.rb', line 28

def level(level = nil)
  @level = normalize(level, DEFAULT_LEVEL)
end

.puts(level, message) ⇒ Object

Emit a message at the given level, if the threshold admits it. Both 'info' and :info are accepted, because plugins pass both.



42
43
44
45
46
47
48
# File 'lib/automatic/log.rb', line 42

def puts(level, message)
  name = normalize(level, DEFAULT_LEVEL)
  return if name == 'none'
  return if LOG_LEVELS.index(name) < LOG_LEVELS.index(current_level)

  logger.public_send(name, message)
end