Sha256: a41c2f9686f252cf94188ec788b30c74f713cde6fcc32a9d0fc4164a7438262c

Contents?: true

Size: 690 Bytes

Versions: 7

Compression:

Stored size: 690 Bytes

Contents

require 'logger'

module Sdbport
  class SdbportLogger
    
    require 'forwardable'

    extend Forwardable

    def_delegators :@logger, :debug, :error, :info, :warn

    def initialize(args = {})
      @log_level = args[:log_level] ||= 'info'
      @logger    = args[:logger] ||= new_logger(args)
    end

    private

    def new_logger(args)
      Logger.new(STDOUT).tap do |l|
        l.datetime_format = '%Y-%m-%dT%H:%M:%S%z'
        l.formatter = proc do |severity, datetime, progname, msg|
          "#{datetime} #{severity} : #{msg}\n"
        end
        l.level = logger_level
      end
    end

    def logger_level
      Logger.const_get @log_level.upcase
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sdbport-0.4.1 lib/sdbport/sdbport_logger.rb
sdbport-0.4.0 lib/sdbport/sdbport_logger.rb
sdbport-0.3.0 lib/sdbport/sdbport_logger.rb
sdbport-0.2.1 lib/sdbport/sdbport_logger.rb
sdbport-0.2.0 lib/sdbport/sdbport_logger.rb
sdbport-0.1.1 lib/sdbport/sdbport_logger.rb
sdbport-0.1.0 lib/sdbport/sdbport_logger.rb