[tor-commits] [stem/master] log_to_stdout() only printed at TRACE level

atagar at torproject.org atagar at torproject.org
Thu Dec 13 16:42:22 UTC 2012


commit a7b275a3d64301da4d23137dbadd4842cc7a041f
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Dec 12 08:13:39 2012 -0800

    log_to_stdout() only printed at TRACE level
    
    Ok, the logging module is *trying* to make me hate it. I haven't a clue what's
    wrong with the basicConfig() function, but when I try to use it the 'level'
    argument is ignored and it always spews its output at the TRACE runlevel. This
    is worthless (trace is often too noisy to be helpful) so making my own
    StdoutLogger.
    
    Tested by running this on a separate system, then copying the change over by
    hand.
---
 stem/util/log.py |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/stem/util/log.py b/stem/util/log.py
index d7a64ea..0def83b 100644
--- a/stem/util/log.py
+++ b/stem/util/log.py
@@ -183,6 +183,17 @@ class LogBuffer(logging.Handler):
   def emit(self, record):
     self._buffer.append(record)
 
+class _StdoutLogger(logging.Handler):
+  def __init__(self, runlevel):
+    logging.Handler.__init__(self, level = logging_level(runlevel))
+    
+    self.formatter = logging.Formatter(
+      fmt = '%(asctime)s [%(levelname)s] %(message)s',
+      datefmt = '%m/%d/%Y %H:%M:%S')
+  
+  def emit(self, record):
+    print self.formatter.format(record)
+
 def log_to_stdout(runlevel):
   """
   Logs further events to stdout.
@@ -190,9 +201,5 @@ def log_to_stdout(runlevel):
   :param stem.util.log.Runlevel runlevel: minimum runlevel a message needs to be to be logged
   """
   
-  logging.basicConfig(
-    level = logging_level(runlevel),
-    format = '%(asctime)s [%(levelname)s] %(message)s',
-    datefmt = '%m/%d/%Y %H:%M:%S',
-  )
+  get_logger().addHandler(_StdoutLogger(runlevel))
 





More information about the tor-commits mailing list