Sha256: 4b1d1c3425991e989404f464b023f7dbcdf15fedc3b7ea9f3855d3ff8ce4cb7c

Contents?: true

Size: 545 Bytes

Versions: 3

Compression:

Stored size: 545 Bytes

Contents

require 'tmpdir'
require 'logger'

module Xi::Logger
  LOG_FILE = File.join(Dir.tmpdir, 'xi.log')

  def logger
    @@logger ||= begin
      logger = ::Logger.new(LOG_FILE)
      logger.formatter = proc do |severity, datetime, progname, msg|
        "[#{datetime.strftime("%F %T %L")}] #{msg}\n"
      end
      logger
    end
  end

  def debug(*args)
    logger.debug(args.map(&:to_s).join(' '.freeze))
  end

  def error(error)
    logger.error("#{error}:\n#{error.backtrace.join("\n".freeze)}")
    ErrorLog.instance << error.to_s
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xi-lang-0.1.5 lib/xi/logger.rb
xi-lang-0.1.4 lib/xi/logger.rb
xi-lang-0.1.3 lib/xi/logger.rb