Sha256: e075294fa3848d0d7edf124f82d67f2c70ecbfb1722e538fbbf05b5deb56408f

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

require 'logger'

module Config
  module Factory

    class << self
      attr_writer :log
    end

    # Gets the logger for the module. Default logger logs to `$stdout`.
    # @return [Logger] the logger
    def self.log
      self.log_device = $stdout unless @log
      @log
    end

    # Sets the log device. Defaults to `$stdout`
    # @param value [IO] the log device
    def self.log_device=(value)
      @log = new_logger(logdev: value)
    end

    def self.new_logger(logdev:, level: Logger::DEBUG, shift_age: 10, shift_size: 1024 * 1024)
      logger = Logger.new(logdev, shift_age, shift_size)
      logger.level = level
      logger.formatter = proc do |severity, datetime, progname, msg|
        "#{datetime.to_time.utc} #{severity} -#{progname}- #{msg}\n"
      end
      logger
    end
    private_class_method :new_logger

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
config-factory-0.1.0 lib/config/factory/log.rb