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

Version Path
fedux_org-stdlib-0.7.21 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.20 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.19 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.18 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.17 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.16 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.15 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.14 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.12 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.11 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.10 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.8 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.7 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.6 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.5 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.4 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.3 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.2 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.1 lib/fedux_org_stdlib/logging/logger.rb
fedux_org-stdlib-0.7.0 lib/fedux_org_stdlib/logging/logger.rb