Sha256: 73f2556ab39fc89aee4ca05fffacd5b7d8345a93b3610d5d00c8ef2b53138d71
Contents?: true
Size: 1.74 KB
Versions: 64
Compression:
Stored size: 1.74 KB
Contents
# encoding: utf-8 require 'fedux_org_stdlib/require_files' require_library %w{ logger forwardable } require 'fedux_org_stdlib/logging/severity' module FeduxOrgStdlib module Logging class Logger extend ::Forwardable def_delegators :@logger, :fatal, :warn, :debug, :info, :error, :unknown attr_reader :mode # Create logger # # @param [Logger] logger (::Logger.new( $stderr )) # The logger with should be used to output data def initialize(logger = ::Logger.new( $stderr ) ) @logger = logger self.mode = :info end # Reset logger to ruby logger def reset @logger = ::Logger.new( $stderr ) end # Change mode of logger: DEBUG, ... + Change the output format # # @param [Symbol] m # the mode: DEBUG, ... def mode=(m) @mode = m case m when :debug @logger.level = ::Logger::DEBUG format_debug when :silent @logger.level = ::Logger::SILENT when :info @logger.level = ::Logger::INFO format_standard else @logger.level = ::Logger::INFO format_standard end end private def format_debug @logger.formatter = proc { |severity, datetime, progname , msg| debug_msg("%s %s %s: %s\n" % [ datetime, severity, progname, msg ]) } end def format_standard @logger.formatter = proc { |severity, datetime, _, msg| info_msg( "%s %s: %s\n" % [ datetime, severity, msg ] ) } end def error_msg(msg) ANSI.red(msg) end def info_msg(msg) msg end def debug_msg(msg) msg end end end end
Version data entries
64 entries across 64 versions & 1 rubygems