Sha256: a24bd9a98f17843b07d50da0f20ede2fccddc049a5a91634b824d7e132d2cdda

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require "logger"

require_relative "default_configuration"

module Lita
  # Creates a Logger with the proper configuration.
  # @api private
  module Logger
    class << self
      # Creates a new {::Logger} outputting to standard error with the given
      # severity level and a custom format.
      # @param level [Symbol, String] The name of the log level to use.
      # @param formatter [Proc] A proc to produce a custom log message format.
      # @param io [String, IO] Where to write the logs. When this value is a +String+, logs will be
      #   written to the named file. When this value is an +IO+, logs will be written to the +IO+.
      # @return [::Logger] The {::Logger} object.
      def get_logger(level, formatter: DefaultConfiguration::DEFAULT_LOG_FORMATTER, io: $stderr)
        logger = ::Logger.new(io)
        logger.progname = "lita"
        logger.level = get_level_constant(level)
        logger.formatter = formatter if formatter
        logger
      end

      private

      # Gets the Logger constant for the given severity level.
      def get_level_constant(level)
        if level
          begin
            ::Logger.const_get(level.to_s.upcase)
          rescue NameError
            ::Logger::INFO
          end
        else
          ::Logger::INFO
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rita-5.0.0.alpha.4 lib/lita/logger.rb
rita-5.0.0.alpha.3 lib/lita/logger.rb
rita-5.0.0.alpha.2 lib/lita/logger.rb
rita-5.0.0.alpha.1 lib/lita/logger.rb