[Yt-svn] yt: Merge

hg at spacepope.org hg at spacepope.org
Thu Apr 22 11:10:48 PDT 2010


hg Repository: yt
details:   yt/rev/f7da016e73fe
changeset: 1587:f7da016e73fe
user:      Matthew Turk <matthewturk at gmail.com>
date:
Thu Apr 22 11:10:44 2010 -0700
description:
Merge

diffstat:

 yt/config.py |   1 +
 yt/logger.py |  26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 0 deletions(-)

diffs (47 lines):

diff -r d9dc71c21f5f -r f7da016e73fe yt/config.py
--- a/yt/config.py	Thu Apr 22 11:08:18 2010 -0700
+++ b/yt/config.py	Thu Apr 22 11:10:44 2010 -0700
@@ -54,6 +54,7 @@
         'time_functions': 'False',
         'LogFile': 'False',
         'LogFileName': 'yt.log',
+        'coloredlogs': 'False',
         'suppressStreamLogging': 'False',
         'LogLevel': '20',
         'timefunctions':'False',
diff -r d9dc71c21f5f -r f7da016e73fe yt/logger.py
--- a/yt/logger.py	Thu Apr 22 11:08:18 2010 -0700
+++ b/yt/logger.py	Thu Apr 22 11:10:44 2010 -0700
@@ -28,6 +28,32 @@
 import logging.handlers as handlers
 from yt.config import ytcfg
 
+# This next bit is grabbed from:
+# http://stackoverflow.com/questions/384076/how-can-i-make-the-python-logging-output-to-be-colored
+def add_coloring_to_emit_ansi(fn):
+    # add methods we need to the class
+    def new(*args):
+        levelno = args[1].levelno
+        if(levelno>=50):
+            color = '\x1b[31m' # red
+        elif(levelno>=40):
+            color = '\x1b[31m' # red
+        elif(levelno>=30):
+            color = '\x1b[33m' # yellow
+        elif(levelno>=20):
+            color = '\x1b[32m' # green 
+        elif(levelno>=10):
+            color = '\x1b[35m' # pink
+        else:
+            color = '\x1b[0m' # normal
+        args[1].msg = color + args[1].msg +  '\x1b[0m'  # normal
+        #print "after"
+        return fn(*args)
+    return new
+
+if ytcfg.getboolean("yt","coloredlogs"):
+    logging.StreamHandler.emit = add_coloring_to_emit_ansi(logging.StreamHandler.emit)
+
 level = min(max(ytcfg.getint("yt", "loglevel"), 0), 50)
 fstring = "%(name)-10s %(levelname)-10s %(asctime)s %(message)s"
 logging.basicConfig(



More information about the yt-svn mailing list