Class: RLog

Inherits:
Object
  • Object
show all
Defined in:
lib/rlog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ RLog

Returns a new instance of RLog.



4
5
6
7
8
9
10
# File 'lib/rlog.rb', line 4

def initialize filename
  unless FileTest.exists?(filename)
    @filename = File.new(filename, "w")
  else
    @filename = File.open(filename, "a")
  end
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



2
3
4
# File 'lib/rlog.rb', line 2

def filename
  @filename
end

#levelObject

Returns the value of attribute level.



3
4
5
# File 'lib/rlog.rb', line 3

def level
  @level
end

Instance Method Details

#log(message) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/rlog.rb', line 18

def log message
  unless @level == nil
    @filename.write("LOGGER:#{@level} => #{message} => #{Time.now}\n")
    @filename.flush
  else
    raise StandardError, "Level not set."
  end
end