Sha256: 7ba2d44e55bb6c3c8975c4e1c943e4376779cca3cb6e4308eb79bc61cc54cd81

Contents?: true

Size: 851 Bytes

Versions: 1

Compression:

Stored size: 851 Bytes

Contents

module Pakyow
  
  # Provides an easy way to log text, warnings, etc.
  class Log
    # Opens stdout and the log file for writing.
    def self.reopen
      @@console = $stdout

      d = Configuration::Base.app.log_dir
      @@file = File.exists?(d) ? File.open("#{d}/#{Configuration::Base.app.log_name}", 'a') : nil
    end

    def self.close
      @@file.close if @@file
    end

    # Adds text to the log. 
    def self.puts(text = "")
      return if !Configuration::Base.app.log
      
      @@console << "#{text}\r\n"
      @@file.write "#{text}\r\n" if @@file
    end

    class << self
      alias :enter :puts
    end
    
    # Adds warning text to the log.
    def self.warn(text)
      Log.enter("WARNING: #{text}")
    end

    # Adds error text to the log.
    def self.error(text)
      Log.enter("ERROR: #{text}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pakyow-core-0.8rc1 pakyow-core/lib/core/log.rb