Class: LoggerLite::Logger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_location = $stdout, mode = "append", startmsg = nil) ⇒ Logger

Returns a new instance of Logger.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/logger_lite.rb', line 8

def initialize(log_location=$stdout, mode="append", startmsg=nil)
  self.log_location = log_location
  if ! ["write", "append"].include? mode then raise ArgumentError, "#{mode} not supported." end
  mode = mode == "write" ? "w" : "a"

  self.handle = File.open(self.log_location, mode)
  
  if startmsg != nil
    data = "[#{Time.now}] - START - #{startmsg}\n"
    self.handle.write data
  end
end

Instance Attribute Details

#handleObject

Returns the value of attribute handle.



6
7
8
# File 'lib/logger_lite.rb', line 6

def handle
  @handle
end

#log_locationObject

Returns the value of attribute log_location.



5
6
7
# File 'lib/logger_lite.rb', line 5

def log_location
  @log_location
end

Instance Method Details

#end_session(data) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/logger_lite.rb', line 36

def end_session(data)
  if data == nil
    self.handle.close
  else
    data = "[#{Time.now}] - END - #{data}\n"
    self.handle.write(data)
    self.handle.close
  end
end

#error(e) ⇒ Object



21
22
23
24
# File 'lib/logger_lite.rb', line 21

def error(e)
  data = "[#{Time.now}] - ERROR - #{e}\n"
  self.handle.write(data)
end

#log(l) ⇒ Object



26
27
28
29
# File 'lib/logger_lite.rb', line 26

def log(l)
  data = "[#{Time.now}] - INFO - #{l}\n"
  self.handle.write(data)
end

#warning(w) ⇒ Object



31
32
33
34
# File 'lib/logger_lite.rb', line 31

def warning(w)
  data = "[#{Time.now}] - ERROR - #{w}\n"
  self.handle.write(data)
end