Module: Logging

Included in:
AptAddToFreightLibrary, AptStageArtifacts, AptStageFromTarball, AptUpdateFreightCache
Defined in:
lib/mixins/logging.rb

Overview

Handles all logging output for Tefoji

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.logger(log_level) ⇒ Object

Do the actual logging by wrapping Logger gem.



20
21
22
23
24
25
26
27
28
# File 'lib/mixins/logging.rb', line 20

def self.logger(log_level)
  return @logger unless @logger.nil?

  @logger = Logger.new($stderr, progname: File.basename($PROGRAM_NAME), level: log_level)
  @logger.formatter = proc do |severity, _, script_name, message|
    "#{script_name}: #{severity} #{message}\n"
  end
  return @logger
end

Instance Method Details

#fatal(message) ⇒ Object

Another cheap hack to wrap 'logger' above. Called as 'fatal' rather than 'logger.fatal' directly, does the exit for us so we can be lazy.



14
15
16
17
# File 'lib/mixins/logging.rb', line 14

def fatal(message)
  logger.fatal(message)
  exit 1
end

#loggerObject

A cheap hack that will instantiate a logger if necessary before sending a log message. This is the normal interface to logging from outside.



8
9
10
# File 'lib/mixins/logging.rb', line 8

def logger
  Logging.logger(@log_level)
end