Sha256: c01ca0689aaa4a3a1e9b60e92c04567f9a6aad1d94774655eb42a0898187ac1b

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

# takelage logging module
module LoggingModule
  # takelage logger
  class TakelageLogger
    include Singleton

    attr_accessor :logger

    def initialize
      @logger = Logger.new(STDOUT)
    end
  end

  # Initialize logger with loglevel.
  def initialize_logging(loglevel)
    TakelageLogger.instance.logger.formatter = _logging_get_log_format
    log_level_in_use = _logging_get_log_level loglevel
    TakelageLogger.instance.logger.level = log_level_in_use
    TakelageLogger.instance.logger.debug "Using loglevel #{log_level_in_use}"
  end

  # @return [Object] global singleton logger
  def log
    TakelageLogger.instance.logger
  end

  private

  # Get log format.
  def _logging_get_log_format
    proc do |severity, _datetime, _progname, msg|
      "[#{severity}] #{msg}\n"
    end
  end

  # Get log level.
  def _logging_get_log_level(loglevel)
    if %w[FATAL ERROR WARN INFO DEBUG].include? loglevel
      loglevel
    else
      TakelageLogger.instance.logger.error 'The parameter "loglevel"' \
          ' must be one of FATAL, ERROR, WARN, INFO, DEBUG'
      TakelageLogger.instance.logger.info 'Using loglevel INFO'
      Logger::INFO
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
takelage-0.22.0 lib/takelage/lib/logging.rb
takelage-0.21.1 lib/takelage/lib/logging.rb
takelage-0.21.0 lib/takelage/lib/logging.rb
takelage-0.20.2 lib/takelage/lib/logging.rb
takelage-0.20.1 lib/takelage/lib/logging.rb
takelage-0.20.0 lib/takelage/lib/logging.rb