repo.or.cz
/
ruby-svn.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git]
/
sample
/
drb
/
dlogd.rb
blob
9f9aa2fd567da2a229d7649c56a45def75535cd2
1
=begin
2
distributed Ruby --- Log server
3
Copyright (c) 1999-2000 Masatoshi SEKI
4
=end
5
6
require 'drb/drb'
7
require 'thread'
8
9
class Logger
10
def initialize(fname)
11
@fname = fname.to_s
12
@fp = File.open(@fname, "a+")
13
@queue = Queue.new
14
@th = Thread.new { self.flush }
15
end
16
17
def log(str)
18
@queue.push("#{Time.now}\t" + str.to_s)
19
end
20
21
def flush
22
begin
23
while(1)
24
@fp.puts(@queue.pop)
25
@fp.flush
26
end
27
ensure
28
@fp.close
29
end
30
end
31
end
32
33
if __FILE__ == $0
34
here = ARGV.shift
35
DRb.start_service(here, Logger.new('/usr/tmp/dlogd.log'))
36
puts DRb.uri
37
DRb.thread.join
38
end
39