Class: TopNotify::Logger
- Inherits:
-
Object
- Object
- TopNotify::Logger
- Defined in:
- lib/top_notify/logger.rb
Instance Method Summary collapse
-
#initialize(device) ⇒ Logger
constructor
A new instance of Logger.
- #log(msg) ⇒ Object
- #log_stream(data, msg = nil) ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize(device) ⇒ Logger
Returns a new instance of Logger.
3 4 5 6 7 8 9 10 |
# File 'lib/top_notify/logger.rb', line 3 def initialize(device) @device = if device.respond_to?(:write) device else File.open(device, 'a') end @device.sync = true if @device.respond_to?(:sync) end |
Instance Method Details
#log(msg) ⇒ Object
12 13 14 |
# File 'lib/top_notify/logger.rb', line 12 def log(msg) @device.write(msg) end |
#log_stream(data, msg = nil) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/top_notify/logger.rb', line 16 def log_stream(data, msg = nil) content = "# #{time}" content += " (#{msg})" if msg content += " [#{data}]\n" log content end |
#time ⇒ Object
23 24 25 |
# File 'lib/top_notify/logger.rb', line 23 def time Time.now.strftime('%Y-%m-%d %H:%M:%S') end |