Sha256: f5dad680413907ce87ad0338a848440e0bc0ac7f7d262af13d3cf0f260c77f0e

Contents?: true

Size: 957 Bytes

Versions: 29

Compression:

Stored size: 957 Bytes

Contents

require 'logger'

class KuberKit::Tools::LoggerFactory
  SEVERITY_COLORS_BY_LEVEL = {
    Logger::INFO   => String::Colors::GREEN,
    Logger::WARN   => String::Colors::PURPLE,
    Logger::DEBUG  => String::Colors::YELLOW,
    Logger::ERROR  => String::Colors::RED,
    Logger::FATAL  => String::Colors::PURPLE,
  }

  def create(stdout, level = nil)
    logger = Logger.new(stdout)

    logger.level = level || Logger::DEBUG

    logger.formatter = proc do |severity, datetime, progname, msg|
      level = Logger::SEV_LABEL.index(severity)

      severity_color = SEVERITY_COLORS_BY_LEVEL[level]

      severity_text  = severity.to_s
      severity_text  = severity_text.colorize(severity_color) if severity_color

      if level == Logger::INFO
        "#{datetime.strftime("%Y/%m/%d %H:%M:%S").grey} #{msg}\n"
      else
        "#{datetime.strftime("%Y/%m/%d %H:%M:%S").grey} #{severity_text.downcase}: #{msg}\n"
      end
    end

    logger
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
kuber_kit-0.3.8 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.3.7 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.3.6 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.3.5 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.3.4 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.3.3 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.3.2 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.3.1 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.3.0 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.9 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.8 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.7 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.6 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.5 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.4 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.3 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.2 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.1 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.2.0 lib/kuber_kit/tools/logger_factory.rb
kuber_kit-0.1.9 lib/kuber_kit/tools/logger_factory.rb