module YleTf::Logger

Logger for debug, error, etc. outputs. Prints to STDERR, so it does not mess with e.g. `terraform output`.

Constants

DEVICE
LEVELS

Public Class Methods

color(severity) click to toggle source
# File lib/yle_tf/logger.rb, line 57
def self.color(severity)
  return if !color?

  case severity.to_s
  when 'FATAL', 'ERROR'
    :red
  when 'WARN'
    :brown
  end
end
color=(value) click to toggle source
# File lib/yle_tf/logger.rb, line 53
def self.color=(value)
  @color = value
end
color?() click to toggle source
# File lib/yle_tf/logger.rb, line 49
def self.color?
  @color
end
log_formatter() click to toggle source
# File lib/yle_tf/logger.rb, line 37
def self.log_formatter
  proc do |severity, _datetime, progname, msg|
    msg = Colorize.colorize(msg, color(severity))

    if progname
      "#{severity}: [#{progname}] #{msg}\n"
    else
      "#{severity}: #{msg}\n"
    end
  end
end
log_level() click to toggle source
# File lib/yle_tf/logger.rb, line 31
def self.log_level
  (ENV['TF_DEBUG'] && 'DEBUG') || \
    ENV['TF_LOG'] || \
    'INFO'
end
logger() click to toggle source
# File lib/yle_tf/logger.rb, line 24
def self.logger
  @logger ||= ::Logger.new(DEVICE).tap do |logger|
    logger.level = log_level
    logger.formatter = log_formatter
  end
end