Sha256: aa065eb586e022ca2a710e50c34758ad1a367e482ab5429e730717b75f39aa73

Contents?: true

Size: 972 Bytes

Versions: 1

Compression:

Stored size: 972 Bytes

Contents

# frozen_string_literal: true

require 'English'
require 'logger'

require 'colorize'

class Logger
  class Formatter
    def call severity, time, _progname, msg
      color = case severity
              when 'DEBUG' then :light_magenta
              when 'INFO' then :light_green
              when 'WARN' then :light_cyan
              when 'ERROR' then :light_red
              when 'FATAL', 'UNKNOWN' then :red
              end

      "[#{severity.ljust(5, ' ').colorize color}][#{time}]: #{msg}\n"
    end
  end
end

module WhatupLogger
  # Access a logger, to stdout (for now).
  #
  # Uses logging level ENV['WHATUP_LOG_LEVEL'], which can be WARN, INFO, etc
  def log
    Logger.new(STDOUT).tap do |logger|
      if Logger.constants.map(&:to_s).include? ENV['WHATUP_LOG_LEVEL']
        logger.level = Logger.const_get ENV['WHATUP_LOG_LEVEL']
      else
        logger.level = Logger::INFO
        logger.level = 9001 if Whatup.testing?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whatup-0.3.5 lib/whatup/server/logger.rb