Class: RLog
- Inherits:
-
Object
- Object
- RLog
- Defined in:
- lib/rlog.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
-
#initialize(filename) ⇒ RLog
constructor
A new instance of RLog.
- #log(message) ⇒ Object
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
#filename ⇒ Object
Returns the value of attribute filename.
2 3 4 |
# File 'lib/rlog.rb', line 2 def filename @filename end |
#level ⇒ Object
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 unless @level == nil @filename.write("LOGGER:#{@level} => #{message} => #{Time.now}\n") @filename.flush else raise StandardError, "Level not set." end end |