]> git.neil.brown.name Git - plato.git/commitdiff
Trivial tracing python library
authorNeilBrown <neilb@suse.de>
Sat, 21 Apr 2012 10:19:14 +0000 (20:19 +1000)
committerNeilBrown <neilb@suse.de>
Sat, 21 Apr 2012 10:19:14 +0000 (20:19 +1000)
Allows tracing that can easily be turned on/off

Signed-off-by: NeilBrown <neilb@suse.de>
lib/tracing.py [new file with mode: 0644]

diff --git a/lib/tracing.py b/lib/tracing.py
new file mode 100644 (file)
index 0000000..1424377
--- /dev/null
@@ -0,0 +1,19 @@
+
+# trivial library for including tracing in programs
+# It can be turned on with PYTRACE=1 in environment
+
+import os,time,sys
+
+tracing = False
+
+if 'PYTRACE' in os.environ:
+    if os.environ['PYTRACE']:
+        tracing = True
+
+def log(*mesg):
+    if tracing:
+        print time.ctime(),
+        for m in mesg:
+            print m,
+        print
+        sys.stdout.flush()