Sha256: 3381ee06791b5f45e9e41adb1b7b6341a51cab4b5cf23f8f2dfbb9ecc875f4c6
Contents?: true
Size: 1.63 KB
Versions: 6
Compression:
Stored size: 1.63 KB
Contents
# frozen_string_literal: true # :nodoc: module Zakuro # :nodoc: module Output # # 軽量なロガー # @note 本番では使用しない # class Logger LEVELS = { none: -1, debug: 0, info: 1, warn: 2, error: 3 }.freeze LEVEL = LEVELS[:none] # @return [String] 呼び出し位置 attr_reader :location def initialize(location:) @location = location end # # DEBUGレベルの標準出力を行う # # @param [String] messages メッセージ # def debug(*messages) return if LEVEL < LEVELS[:debug] output('DEBUG', *messages) end # # INFOレベルの標準出力を行う # # @param [String] messages メッセージ # def info(*messages) return if LEVEL < LEVELS[:info] output('INFO', *messages) end # # ERRORレベルの標準出力を行う # # @param [Error] error 例外 # @param [String] messages メッセージ # def error(error, *messages) return if LEVEL < LEVELS[:error] output('ERROR', *messages) output('ERROR', error.message) output('ERROR', *error.backtrace) end private # # 標準出力を行う # # @param [String] level ログレベル # @param [String] messages メッセージ # def output(level, *messages) messages.each do |message| # :#{Thread.current.backtrace[5]} p "[#{level}] #{@location}: #{message}" end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems