Sha256: 5673810ce2d7b789a2f0a75026b3d843a8990642893e93554adc4e70809f546e

Contents?: true

Size: 1.24 KB

Versions: 37

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

# tau logging module
module LoggingModule
  # tau logger
  class TakeltauLogger
    include Singleton

    attr_accessor :logger

    def initialize
      @logger = Logger.new($stdout)
    end
  end

  # Initialize logger with loglevel.
  def initialize_logging(loglevel, debug)
    TakeltauLogger.instance.logger.formatter = _logging_get_log_format
    loglevel = 'DEBUG' if debug
    log_level_in_use = _logging_get_log_level loglevel
    TakeltauLogger.instance.logger.level = log_level_in_use
    TakeltauLogger.instance.logger.debug "Using loglevel #{log_level_in_use}"
  end

  # @return [Object] global singleton logger
  def log
    TakeltauLogger.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
      TakeltauLogger.instance.logger.error 'The parameter "loglevel" ' \
                                           'must be one of FATAL, ERROR, WARN, INFO, DEBUG'
      TakeltauLogger.instance.logger.info 'Using loglevel INFO'
      Logger::INFO
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
takeltau-0.46.9 lib/takeltau/lib/logging.rb
takeltau-0.46.8 lib/takeltau/lib/logging.rb
takeltau-0.46.5 lib/takeltau/lib/logging.rb
takeltau-0.46.1 lib/takeltau/lib/logging.rb
takeltau-0.46.0 lib/takeltau/lib/logging.rb
takeltau-0.45.27 lib/takeltau/lib/logging.rb
takeltau-0.45.26 lib/takeltau/lib/logging.rb
takeltau-0.45.24 lib/takeltau/lib/logging.rb
takeltau-0.45.23 lib/takeltau/lib/logging.rb
takeltau-0.45.22 lib/takeltau/lib/logging.rb
takeltau-0.45.21 lib/takeltau/lib/logging.rb
takeltau-0.45.19 lib/takeltau/lib/logging.rb
takeltau-0.45.17 lib/takeltau/lib/logging.rb
takeltau-0.45.16 lib/takeltau/lib/logging.rb
takeltau-0.45.14 lib/takeltau/lib/logging.rb
takeltau-0.45.13 lib/takeltau/lib/logging.rb
takeltau-0.45.12 lib/takeltau/lib/logging.rb
takeltau-0.45.11 lib/takeltau/lib/logging.rb
takeltau-0.45.10 lib/takeltau/lib/logging.rb
takeltau-0.45.9 lib/takeltau/lib/logging.rb