[pypy-svn] r68813 - pypy/branch/logging/pypy/rlib

arigo at codespeak.net arigo at codespeak.net
Wed Oct 28 12:30:44 CET 2009


Author: arigo
Date: Wed Oct 28 12:30:43 2009
New Revision: 68813

Modified:
   pypy/branch/logging/pypy/rlib/rlog_parsing.py
Log:
Move the code to its own function and support limited syntax highlighting.


Modified: pypy/branch/logging/pypy/rlib/rlog_parsing.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/rlog_parsing.py	(original)
+++ pypy/branch/logging/pypy/rlib/rlog_parsing.py	Wed Oct 28 12:30:43 2009
@@ -76,14 +76,8 @@
     logparser = LogParser(open(filename, 'rb'))
     return logparser.enum_entries()
 
-
-if __name__ == '__main__':
-    import sys, re, fnmatch
-    filename = sys.argv[1]
-    if len(sys.argv) > 2:
-        limit = sys.argv[2] + '*'
-    else:
-        limit = '*'
+def dump_log(filename, limit='*', highlight=False):
+    import re
     r_replace = re.compile(r"%\(\w+\)")
     for curtime, cat, entries in parse_log(filename):
         if not fnmatch.fnmatch(cat.category, limit):
@@ -94,5 +88,22 @@
             code = '[%s] ' % cat.category
             message = cat.message.replace('\n', '\n' + ' '*len(code))
             message = r_replace.sub("%", message)
-            printcode = cat.printcode = code + message
+            printcode = code + message
+            if highlight:
+                if cat.category.endswith('{'):
+                    printcode = '\x1B[1m%s\x1B[0m' % (printcode,)
+                elif cat.category.endswith('}'):
+                    printcode = '\x1B[31m%s\x1B[0m' % (printcode,)
+            cat.printcode = printcode
         print printcode % tuple(entries)
+
+
+if __name__ == '__main__':
+    import sys, fnmatch
+    filename = sys.argv[1]
+    if len(sys.argv) > 2:
+        limit = sys.argv[2] + '*'
+    else:
+        limit = '*'
+    highlight = sys.stdout.isatty()
+    dump_log(filename, limit, highlight)



More information about the Pypy-commit mailing list