Class: IoT::Log

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

Overview

Logging events and actions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name = '/tmp/iot.log') ⇒ Log

Returns a new instance of Log.



10
11
12
# File 'lib/iot.rb', line 10

def initialize(file_name='/tmp/iot.log')
  @file_name = file_name
end

Instance Attribute Details

#file_nameObject

Returns the value of attribute file_name.



8
9
10
# File 'lib/iot.rb', line 8

def file_name
  @file_name
end

Instance Method Details

#message(type = 'I', text = 'OK') ⇒ Object

Message types: I = Info, W = Warning, E = Error, F = Fatal error



15
16
17
18
19
# File 'lib/iot.rb', line 15

def message(type='I', text='OK')
  File.open(@file_name, 'w+') do |log|
    log.printf "%s %s %s\n", Time.now.strftime("%Y%m%d %H%M%S"), type, text
  end
end