class Pione::Log::PioneSystemLogger
‘Log::PioneSystemLogger` is a PIONE original logger. This generates very colorful message for identifiability and detailed informations.
Attributes
level[RW]
Public Class Methods
new(out = nil)
click to toggle source
Calls superclass method
Pione::Log::BasicLogger::new
# File lib/pione/log/system-log.rb, line 52 def initialize(out = nil) super() @queue = Queue.new @thread = make_writer_thread @lock = Mutex.new @out = out end
Public Instance Methods
debug(msg, pos=caller(1).first, pid=Process.pid)
click to toggle source
# File lib/pione/log/system-log.rb, line 65 def debug(msg, pos=caller(1).first, pid=Process.pid); push(:debug, msg, pos, pid); end
error(msg, pos=caller(1).first, pid=Process.pid)
click to toggle source
# File lib/pione/log/system-log.rb, line 62 def error(msg, pos=caller(1).first, pid=Process.pid); push(:error, msg, pos, pid); end
fatal(msg, pos=caller(1).first, pid=Process.pid)
click to toggle source
# File lib/pione/log/system-log.rb, line 61 def fatal(msg, pos=caller(1).first, pid=Process.pid); push(:fatal, msg, pos, pid); end
info(msg, pos=caller(1).first, pid=Process.pid)
click to toggle source
# File lib/pione/log/system-log.rb, line 64 def info (msg, pos=caller(1).first, pid=Process.pid); push(:info , msg, pos, pid); end
queued?()
click to toggle source
# File lib/pione/log/system-log.rb, line 86 def queued? not(@queue.empty?) end
terminate()
click to toggle source
# File lib/pione/log/system-log.rb, line 67 def terminate timeout(3) do while @thread.alive? if @queue.empty? and not(@lock.locked?) @thread.kill.join break else sleep 0.1 end end end rescue Timeout::Error # don't use logger here because it is dead at this time $stdout.puts("*** system logger has been terminated unsafety, some messages maybe lost ***") ensure # kill writer thread @thread.kill if @thread.alive? end
warn(msg, pos=caller(1).first, pid=Process.pid)
click to toggle source
# File lib/pione/log/system-log.rb, line 63 def warn (msg, pos=caller(1).first, pid=Process.pid); push(:warn , msg, pos, pid); end
Private Instance Methods
color_of(level)
click to toggle source
# File lib/pione/log/system-log.rb, line 107 def color_of(level) Global.send("pione_system_logger_%s" % level) end
make_writer_thread()
click to toggle source
# File lib/pione/log/system-log.rb, line 92 def make_writer_thread Thread.new do while true do level, msg, pos, pid, time = @queue.pop @lock.synchronize {print(level, msg, pos, pid, time)} end end end
print(level, msg, pos, pid, time)
click to toggle source
# File lib/pione/log/system-log.rb, line 111 def print(level, msg, pos, pid, time) out = @out || $stdout if level == :info out.puts "%s: %s" % [level.to_s.color(color_of(level)), msg] else out.puts "%s: %s [%s] (%s, #%s)" % [level.to_s.color(color_of(level)), msg, pos, time.iso8601(3), pid] end end
push(level, msg, pos, pid)
click to toggle source
# File lib/pione/log/system-log.rb, line 101 def push(level, msg, pos, pid) if loggable?(level) @queue.push([level, msg, pos, pid, Time.now]) end end