Sha256: 12753d6a1dc0113c0d2544bfc411e8989549ee6f53f4b1070b9cfc3ec4ac6634

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 KB

Contents

require 'logatron/const'
require 'logatron/basic_logger'
require 'logatron/message_formatting'
require 'logatron/configuration'

module Logatron
  class BasicScopedLogger
    include Logatron::Formatting

    def initialize(logger)
      @logger = logger
      @logs = Hash[Logatron::SEVERITY_MAP.keys.map { |key| [key, []] }]
    end

    def info(msg)
      write(format_log(msg: msg, severity: INFO), INFO)
    end

    def warn(msg)
      write(format_log(msg: msg, severity: WARN), WARN)
    end

    def debug(msg)
      write(format_log(msg: msg, severity: DEBUG), DEBUG)
    end

    def invalid_use(msg)
      write(format_log(msg: msg, severity: INVALID_USE), INVALID_USE)
    end

    def error(msg)
      write(format_log(msg: msg, severity: ERROR), ERROR)
    end

    def critical(msg)
      write(format_log(msg: msg, severity: CRITICAL), CRITICAL)
    end

    def fatal(msg)
      write(format_log(msg: msg, severity: FATAL), FATAL)
    end

    def write(string, severity = INFO)
      @logs[severity].push string
    end

    def flush
      Logatron.configuration.loggable_levels.each do |key|
        @logs[key].each do |item|
          @logger.write(item, SEVERITY_MAP[key])
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
logatron-0.16.1 lib/logatron/basic_scoped_logger.rb
logatron-0.16.0 lib/logatron/basic_scoped_logger.rb
logatron-0.15.0 lib/logatron/basic_scoped_logger.rb
logatron-0.14.0 lib/logatron/basic_scoped_logger.rb
logatron-0.13.0 lib/logatron/basic_scoped_logger.rb
logatron-0.12.0 lib/logatron/basic_scoped_logger.rb
logatron-0.11.0 lib/logatron/basic_scoped_logger.rb
logatron-0.10.0 lib/logatron/basic_scoped_logger.rb
logatron-0.9.0 lib/logatron/basic_scoped_logger.rb
logatron-0.8.0 lib/logatron/basic_scoped_logger.rb
logatron-0.7.0 lib/logatron/basic_scoped_logger.rb
logatron-0.6.0 lib/logatron/basic_scoped_logger.rb
logatron-0.5.0 lib/logatron/basic_scoped_logger.rb