Sha256: 47295d7f0684a3cbcef97f3809a00076b46ddd2a8510d4a5a476318ae9143271

Contents?: true

Size: 640 Bytes

Versions: 1

Compression:

Stored size: 640 Bytes

Contents

require 'logger'

module Alfa
  class Logger < ::Logger

    def initialize(logdev, shift_age = 0, shift_size = 1048576)
      super
      @formatter = Formatter.new
    end

    def portion(&block)
      io = VirtualIO.new
      l = ::Logger.new(io)
      l.formatter = @formatter
      yield(l)
      self << io.join
      l = nil
      io = nil
    end

    private

    class VirtualIO < ::Array
      def write(message)
        self.push message
      end

      def close
      end
    end

    class Formatter < ::Logger::Formatter
      def call(severity, time, progname, msg)
        msg2str("#{msg}\n")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alfa-0.0.2.pre lib/alfa/logger.rb