Sha256: dd06b69ec4392113502473127d2efa0ab10f1940f92bd478f688912b57b46ddb

Contents?: true

Size: 967 Bytes

Versions: 19

Compression:

Stored size: 967 Bytes

Contents

module Lita
  # Creates a Logger with the proper configuration.
  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.
      # @return [::Logger] The {::Logger} object.
      def get_logger(level)
        logger = ::Logger.new(STDERR)
        logger.level = get_level_constant(level)
        logger.formatter = proc do |severity, datetime, progname, msg|
          "[#{datetime.utc}] #{severity}: #{msg}\n"
        end
        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
            return ::Logger::INFO
          end
        else
          ::Logger::INFO
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
lita-3.1.0 lib/lita/logger.rb
lita-3.0.4 lib/lita/logger.rb
lita-3.0.3 lib/lita/logger.rb
lita-3.0.2 lib/lita/logger.rb
lita-3.0.1 lib/lita/logger.rb
lita-3.0.0 lib/lita/logger.rb
lita-2.7.2 lib/lita/logger.rb
lita-2.7.1 lib/lita/logger.rb
lita-2.7.0 lib/lita/logger.rb
lita-2.6.0 lib/lita/logger.rb
lita-2.5.0 lib/lita/logger.rb
lita-2.4.0 lib/lita/logger.rb
lita-2.3.0 lib/lita/logger.rb
lita-2.2.1 lib/lita/logger.rb
lita-2.2.0 lib/lita/logger.rb
lita-2.1.2 lib/lita/logger.rb
lita-2.1.1 lib/lita/logger.rb
lita-2.1.0 lib/lita/logger.rb
lita-2.0.0 lib/lita/logger.rb