Sha256: 8086155e4e400d19dde1820ad812b10222105ad1b6de86cc0599a05abda2df90

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 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

2 entries across 2 versions & 1 rubygems

Version Path
logatron-0.3.0 lib/logatron/basic_scoped_logger.rb
logatron-0.2.6 lib/logatron/basic_scoped_logger.rb