timestamp lines when using --debug
authorForrest Voight <forrest@forre.st>
Wed, 27 Jul 2011 02:45:13 +0000 (22:45 -0400)
committerForrest Voight <forrest@forre.st>
Wed, 27 Jul 2011 02:45:13 +0000 (22:45 -0400)
p2pool/main.py

index 6f48d38..7e78302 100644 (file)
@@ -572,6 +572,18 @@ def run():
     
     if args.debug:
         p2pool_init.DEBUG = True
+        class TimestampingPipe(object):
+            def __init__(self, inner_file):
+                self.inner_file = inner_file
+                self.buf = ""
+            def write(self, data):
+                buf = self.buf + data
+                lines = buf.split('\n')
+                for line in lines[:-1]:
+                    self.inner_file.write("%s %s\n" % (time.strftime("%H:%M:%S"), line))
+                self.buf = lines[-1]
+        sys.stdout = TimestampingPipe(sys.stdout)
+        sys.stderr = TimestampingPipe(sys.stderr)
     
     if args.bitcoind_p2p_port is None:
         args.bitcoind_p2p_port = args.net.BITCOIN_P2P_PORT