Class: SCGI::Log

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

Overview

A simple Log class that has an info and error method for output messages to a log file. The main thing this logger does is include the process ID in the logs so that you can see which child is creating each message.

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Log

Returns a new instance of Log.



30
31
32
33
34
35
36
37
# File 'lib/scgi.rb', line 30

def initialize(file)
  super()
  @out = open(file, "a+")
  @out.sync = true
  @pid = Process.pid
  @info = "[INF][#{@pid}] "
  @error = "[ERR][#{@pid}] "
end

Instance Method Details

#error(msg, exc = nil) ⇒ Object

If an exception is given then it will print the exception and a stack trace.



44
45
46
47
# File 'lib/scgi.rb', line 44

def error(msg, exc=nil)
  return synchronize{@out.print("#{@error}#{msg}\n")} unless exc
  synchronize{@out.print("#{@error}#{msg}: #{exc}\n#{exc.backtrace.join("\n")}\n")}
end

#info(msg) ⇒ Object



39
40
41
# File 'lib/scgi.rb', line 39

def info(msg)
  synchronize{@out.print("#{@info}#{msg}\n")}
end