Sha256: 2cf12f244e0980cb16f8d577d78e4ad84253ffa1ff8846b37b669e7dfdbfc994

Contents?: true

Size: 1.41 KB

Versions: 24

Compression:

Stored size: 1.41 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 unless defined? SILENT
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.0.35 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.33 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.32 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.31 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.30 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.29 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.28 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.26 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.25 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.24 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.23 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.22 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.21 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.20 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.19 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.17 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.16 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.14 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.13 lib/fedux_org/stdlib/logging/logger.rb
fedux_org-stdlib-0.0.12 lib/fedux_org/stdlib/logging/logger.rb