[yt-svn] commit/yt: xarthisius: Add `NullHandler` to `ytLogger` when stream logging is suppresed. Fixes #492

Bitbucket commits-noreply at bitbucket.org
Sat Feb 2 04:58:07 PST 2013


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/4151cc9ff9b2/
changeset:   4151cc9ff9b2
branch:      yt
user:        xarthisius
date:        2013-02-02 11:03:07
summary:     Add `NullHandler` to `ytLogger` when stream logging is suppresed. Fixes #492
affected #:  1 file

diff -r 100c55efbac229d8b970e89f157bb52bfb1f71a8 -r 4151cc9ff9b2e0c77d215f85582984a9b096eaae yt/utilities/logger.py
--- a/yt/utilities/logger.py
+++ b/yt/utilities/logger.py
@@ -6,7 +6,7 @@
 Affiliation: KIPAC/SLAC/Stanford
 Homepage: http://yt-project.org/
 License:
-  Copyright (C) 2007-2011 Matthew Turk.  All Rights Reserved.
+  Copyright (C) 2007-2013 Matthew Turk.  All Rights Reserved.
 
   This file is part of yt.
 
@@ -24,31 +24,31 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-import logging, os
-import logging.handlers as handlers
+import logging
 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
+        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
+            color = '\x1b[0m'  # normal
         ln = color + args[1].levelname + '\x1b[0m'
         args[1].levelname = ln
-        #print "after"
         return fn(*args)
     return new
 
@@ -61,29 +61,38 @@
 )
 
 rootLogger = logging.getLogger()
+ytLogger = logging.getLogger("yt")
 
-ytLogger = logging.getLogger("yt")
 
 def disable_stream_logging():
     # We just remove the root logger's handlers
     for handler in rootLogger.handlers:
         if isinstance(handler, logging.StreamHandler):
             rootLogger.removeHandler(handler)
+    h = logging.NullHandler()
+    ytLogger.addHandler(h)
 
 original_emitter = logging.StreamHandler.emit
+
+
 def colorize_logging():
     f = logging.Formatter(cfstring)
-    if len(rootLogger.handlers) > 0: rootLogger.handlers[0].setFormatter(f)
-    logging.StreamHandler.emit = add_coloring_to_emit_ansi(logging.StreamHandler.emit)
+    if len(rootLogger.handlers) > 0:
+        rootLogger.handlers[0].setFormatter(f)
+    logging.StreamHandler.emit = add_coloring_to_emit_ansi(
+        logging.StreamHandler.emit)
+
+
 def uncolorize_logging():
     f = logging.Formatter(ufstring)
-    if len(rootLogger.handlers) > 0: rootLogger.handlers[0].setFormatter(f)
+    if len(rootLogger.handlers) > 0:
+        rootLogger.handlers[0].setFormatter(f)
     logging.StreamHandler.emit = original_emitter
 
-if ytcfg.getboolean("yt","coloredlogs"):
+if ytcfg.getboolean("yt", "coloredlogs"):
     colorize_logging()
 
-if ytcfg.getboolean("yt","suppressStreamLogging"):
+if ytcfg.getboolean("yt", "suppressStreamLogging"):
     disable_stream_logging()
 
 ytLogger.debug("Set log level to %s", level)

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list