From: Aki Tuomi Date: Wed, 28 May 2014 07:36:46 +0000 (+0300) Subject: Fix logging to use class variable to avoid multiple file opens X-Git-Tag: rec-3.6.0~19^2~15^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27259f8be2f0bba84cc6e99c7583439915b4cb24;p=thirdparty%2Fpdns.git Fix logging to use class variable to avoid multiple file opens --- diff --git a/modules/remotebackend/regression-tests/dnsbackend.rb b/modules/remotebackend/regression-tests/dnsbackend.rb index 35de50207f..0278dd2705 100644 --- a/modules/remotebackend/regression-tests/dnsbackend.rb +++ b/modules/remotebackend/regression-tests/dnsbackend.rb @@ -5,8 +5,11 @@ class DNSBackendHandler < WEBrick::HTTPServlet::AbstractServlet def initialize(server, dnsbackend) @dnsbackend = dnsbackend @semaphore = Mutex.new - @f = File.open("/tmp/remotebackend.txt.#{$$}","a") - @f.sync + unless defined? @@f + @@f = File.open("/tmp/remotebackend.txt.#{$$}","a") + @@f.sync + end + @dnsbackend.do_initialize({}) end def parse_arrays(params) @@ -103,7 +106,7 @@ class DNSBackendHandler < WEBrick::HTTPServlet::AbstractServlet args = parse_arrays args - @f.puts "#{Time.now.to_f} [http]: #{({:method=>method,:parameters=>args}).to_json}" + @@f.puts "#{Time.now.to_f} [http]: #{({:method=>method,:parameters=>args}).to_json}" @semaphore.synchronize do if @dnsbackend.respond_to?(method.to_sym) @@ -117,7 +120,7 @@ class DNSBackendHandler < WEBrick::HTTPServlet::AbstractServlet res["Content-Type"] = "application/javascript; charset=utf-8" res.body = ({:result => false, :log => ["Method not found"]}).to_json end - @f.puts "#{Time.now.to_f} [http]: #{res.body}" + @@f.puts "#{Time.now.to_f} [http]: #{res.body}" end end