[tor-commits] [stem/master] Improving system TRACE logging

atagar at torproject.org atagar at torproject.org
Fri Jan 6 06:45:17 UTC 2012


commit 21e8f65ad3e981f0060eb0fc71c2c432f32194b0
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Jan 5 18:39:41 2012 -0800

    Improving system TRACE logging
    
    Showing request/reply with a debug level message for system calls with runtime
    is redundant. In case of a call failure we just need to give a debug, and in
    success we show the debug followed by an improved trace message.
---
 stem/util/system.py |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/stem/util/system.py b/stem/util/system.py
index 5b6d9fe..3e086c7 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -582,22 +582,24 @@ def call(command, suppress_exc = True):
   
   try:
     start_time = time.time()
-    log.trace("Sent to system:\n" + command)
     stdout, stderr = subprocess.Popen(command.split(), stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
     stdout, stderr = stdout.strip(), stderr.strip()
     runtime = time.time() - start_time
     
-    if not stderr:
-      log.trace("Received from system:\n" + stdout)
-    else:
-      log.trace("Received from system:\nstdout: %s\nstderr: %s" % (stdout, stderr))
+    log.debug("System call: %s (runtime: %0.2f)" % (command, runtime))
+    trace_prefix = "Received from system (%s)" % command
     
-    log.debug("system call: %s (runtime: %0.2f)" % (command, runtime))
+    if stdout and stderr:
+      log.trace(trace_prefix + ", stdout:\n%s\nstderr:\n%s" % (stdout, stderr))
+    elif stdout:
+      log.trace(trace_prefix + ", stdout:\n%s" % stdout)
+    elif stderr:
+      log.trace(trace_prefix + ", stderr:\n%s" % stderr)
     
     if stdout: return stdout.split("\n")
     else: return []
   except OSError, exc:
-    log.debug("system call (failed): %s (error: %s)" % (command, exc))
+    log.debug("System call (failed): %s (error: %s)" % (command, exc))
     
     if suppress_exc: return None
     else: raise exc





More information about the tor-commits mailing list