Sha256: 015eb0f44ce16ae6b63110c3a72787393aa0ae04d046ece59786df0ff6ead2e0

Contents?: true

Size: 591 Bytes

Versions: 4

Compression:

Stored size: 591 Bytes

Contents

require 'logger'
require 'fileutils'

module Kernel
  def log(*msgs)
    $logger.log(*msgs)
  end
end

module Space
  class Logger < ::Logger
    def initialize(path)
      truncate
      super
      self.formatter = ->(severity, datetime, progname, msg) { "#{msg}\n" }
    end

    def log(*msgs)
      msgs.each do |msg|
        info msg.is_a?(Array) ? msg.join("\n") : msg
      end
    end

    def truncate
      File.open(filename, 'w+') { |f| f.write('-' * 80 + "\n") }
    end

    def filename
      '/tmp/space.log'
    end
  end
end

$logger = Space::Logger.new('/tmp/space.log')

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
space-0.0.9 lib/space/logger.rb
space-0.0.8 lib/space/logger.rb
space-0.0.7 lib/space/logger.rb
space-0.0.6 lib/space/logger.rb