2004-02-13 21:28:02 -05:00
|
|
|
=begin
|
|
|
|
distributed Ruby --- Log server
|
2011-05-15 07:55:52 -04:00
|
|
|
Copyright (c) 1999-2000 Masatoshi SEKI
|
2004-02-13 21:28:02 -05:00
|
|
|
=end
|
|
|
|
|
|
|
|
require 'drb/drb'
|
|
|
|
|
|
|
|
class Logger
|
|
|
|
def initialize(fname)
|
|
|
|
@fname = fname.to_s
|
|
|
|
@fp = File.open(@fname, "a+")
|
2016-08-30 02:22:30 -04:00
|
|
|
@queue = Thread::Queue.new
|
2004-02-13 21:28:02 -05:00
|
|
|
@th = Thread.new { self.flush }
|
|
|
|
end
|
|
|
|
|
|
|
|
def log(str)
|
|
|
|
@queue.push("#{Time.now}\t" + str.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
def flush
|
|
|
|
begin
|
|
|
|
while(1)
|
2013-07-20 09:41:02 -04:00
|
|
|
@fp.puts(@queue.pop)
|
|
|
|
@fp.flush
|
2004-02-13 21:28:02 -05:00
|
|
|
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
|
|
|
|
|