2004-02-14 05:28:02 +03:00
|
|
|
=begin
|
|
|
|
distributed Ruby --- Log server
|
2011-05-15 15:55:52 +04:00
|
|
|
Copyright (c) 1999-2000 Masatoshi SEKI
|
2004-02-14 05:28:02 +03:00
|
|
|
=end
|
|
|
|
|
|
|
|
require 'drb/drb'
|
|
|
|
require 'thread'
|
|
|
|
|
|
|
|
class Logger
|
|
|
|
def initialize(fname)
|
|
|
|
@fname = fname.to_s
|
|
|
|
@fp = File.open(@fname, "a+")
|
|
|
|
@queue = Queue.new
|
|
|
|
@th = Thread.new { self.flush }
|
|
|
|
end
|
|
|
|
|
|
|
|
def log(str)
|
|
|
|
@queue.push("#{Time.now}\t" + str.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
def flush
|
|
|
|
begin
|
|
|
|
while(1)
|
|
|
|
@fp.puts(@queue.pop)
|
|
|
|
@fp.flush
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
@fp.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if __FILE__ == $0
|
|
|
|
here = ARGV.shift
|
|
|
|
DRb.start_service(here, Logger.new('/usr/tmp/dlogd.log'))
|
|
|
|
puts DRb.uri
|
|
|
|
DRb.thread.join
|
|
|
|
end
|
|
|
|
|