Sha256: 9ebe670b26d17787c48009925dfea757c46d05c0a6f4076371c11e2bf860a43d

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

require 'logger'

module FeduxOrg
  module Stdlib
    module Logging
      class Logger

        extend ::Forwardable
        def_delegators :@logger, :fatal, :warn, :debug, :info, :error, :unknown

        attr_reader :mode

        def initialize
          @logger = ::Logger.new($stderr)
          self.mode = :info
        end

        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
end

class ::Logger
  SILENT = 9999
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.0.6 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.5 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.4 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.3 lib/fedux_org/stdlib/logging/logger.rb