[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Record the log output of tor by creating a temporary logfile and reading from it.



commit 02a78452d747648b97acc074d82287dd039b6971
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sat Sep 13 21:00:07 2014 -0400

    Record the log output of tor by creating a temporary logfile and reading from it.
---
 ooni/nettests/blocking/bridge_reachability.py |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/ooni/nettests/blocking/bridge_reachability.py b/ooni/nettests/blocking/bridge_reachability.py
index e0d0d8a..d4f6e13 100644
--- a/ooni/nettests/blocking/bridge_reachability.py
+++ b/ooni/nettests/blocking/bridge_reachability.py
@@ -1,5 +1,7 @@
 # -*- encoding: utf-8 -*-
+import os
 import random
+import tempfile
 from distutils.spawn import find_executable
 
 from twisted.python import usage
@@ -49,6 +51,8 @@ class BridgeReachability(nettest.NetTestCase):
         self.tor_progress = 0
         self.timeout = int(self.localOptions['timeout'])
 
+        _, self.logfile = tempfile.mkstemp()
+
         self.report['error'] = None
         self.report['success'] = None
         self.report['timeout'] = self.timeout
@@ -170,7 +174,7 @@ class BridgeReachability(nettest.NetTestCase):
 
         config.Bridge = self.bridge
         config.UseBridges = 1
-        config.log = 'notice'
+        config.log = ['notice stdout', 'notice file %s' % self.logfile]
         config.save()
 
         def updates(prog, tag, summary):
@@ -194,7 +198,14 @@ class BridgeReachability(nettest.NetTestCase):
         @d.addErrback
         def setup_failed(failure):
             log.msg("Failed to connect to %s" % self.bridge)
-            self.report['tor_log'] = failure.value.message
             self.report['success'] = False
+            self.report['error'] = 'timeout-reached'
+            return
+
+        @d.addCallback
+        def write_log(_):
+            with open(self.logfile) as f:
+                self.report['tor_log'] = f.read()
+            os.remove(self.logfile)
 
         return d



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits