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'
|
|
|
|
|
|
|
|
class Logger
|
|
|
|
def initialize(fname)
|
|
|
|
@fname = fname.to_s
|
|
|
|
@fp = File.open(@fname, "a+")
|
2016-08-30 09:22:30 +03:00
|
|
|
@queue = Thread::Queue.new
|
2004-02-14 05:28:02 +03: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 17:41:02 +04:00
|
|
|
@fp.puts(@queue.pop)
|
|
|
|
@fp.flush
|
2004-02-14 05:28:02 +03: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
|
|
|
|
|