Class: Logger
- Inherits:
-
Object
- Object
- Logger
- Defined in:
- lib/mchat/logger.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(switch) ⇒ Logger
constructor
A new instance of Logger.
- #log(component, info) ⇒ Object
Constructor Details
#initialize(switch) ⇒ Logger
Returns a new instance of Logger.
2 3 4 5 6 7 8 |
# File 'lib/mchat/logger.rb', line 2 def initialize(switch) @switch = switch if @switch == :on @output = File.absolute_path("#{__dir__}/../../log") @f = File.open("#{@output}/#{Time.now.to_s}.log","w+") end end |
Instance Method Details
#close ⇒ Object
14 15 16 |
# File 'lib/mchat/logger.rb', line 14 def close @f.close if @switch == :on end |
#log(component, info) ⇒ Object
10 11 12 |
# File 'lib/mchat/logger.rb', line 10 def log(component, info) @f << "[#{component}]: #{Time.now.to_s}: #{info}\n" if @switch == :on end |