[Yt-svn] yt: Changing colorizing to apply to the level name. Also add an...
hg at spacepope.org
hg at spacepope.org
Tue Jan 25 08:41:00 PST 2011
hg Repository: yt
details: yt/rev/7e6401925805
changeset: 3690:7e6401925805
user: Matthew Turk <matthewturk at gmail.com>
date:
Tue Jan 25 11:40:56 2011 -0500
description:
Changing colorizing to apply to the level name. Also add an uncolorize
function, which gets called during parallel analysis.
diffstat:
yt/utilities/logger.py | 20 +++++++++----
yt/utilities/parallel_tools/parallel_analysis_interface.py | 5 ++-
2 files changed, 18 insertions(+), 7 deletions(-)
diffs (70 lines):
diff -r 8df12c337844 -r 7e6401925805 yt/utilities/logger.py
--- a/yt/utilities/logger.py Mon Jan 24 21:10:49 2011 -0500
+++ b/yt/utilities/logger.py Tue Jan 25 11:40:56 2011 -0500
@@ -46,24 +46,23 @@
color = '\x1b[35m' # pink
else:
color = '\x1b[0m' # normal
- args[1].msg = color + args[1].msg + '\x1b[0m' # normal
+ ln = color + args[1].levelname + '\x1b[0m'
+ args[1].levelname = ln
#print "after"
return fn(*args)
return new
level = min(max(ytcfg.getint("yt", "loglevel"), 0), 50)
-fstring = "%(name)-10s %(levelname)-10s %(asctime)s %(message)s"
+ufstring = "%(name)-3s: [%(levelname)-9s] %(asctime)s %(message)s"
+cfstring = "%(name)-3s: [%(levelname)-18s] %(asctime)s %(message)s"
logging.basicConfig(
- format=fstring,
+ format=ufstring,
level=level
)
-f = logging.Formatter("%(levelname)-10s %(asctime)s %(message)s")
-
rootLogger = logging.getLogger()
ytLogger = logging.getLogger("yt")
-ytLogger.debug("Set log level to %s", level)
def disable_stream_logging():
# We just remove the root logger's handlers
@@ -71,11 +70,20 @@
if isinstance(handler, logging.StreamHandler):
rootLogger.removeHandler(handler)
+original_emitter = logging.StreamHandler.emit
def colorize_logging():
+ f = logging.Formatter(cfstring)
+ rootLogger.handlers[0].setFormatter(f)
logging.StreamHandler.emit = add_coloring_to_emit_ansi(logging.StreamHandler.emit)
+def uncolorize_logging():
+ f = logging.Formatter(ufstring)
+ rootLogger.handlers[0].setFormatter(f)
+ logging.StreamHandler.emit = original_emitter
if ytcfg.getboolean("yt","coloredlogs"):
colorize_logging()
if ytcfg.getboolean("yt","suppressStreamLogging"):
disable_stream_logging()
+
+ytLogger.debug("Set log level to %s", level)
diff -r 8df12c337844 -r 7e6401925805 yt/utilities/parallel_tools/parallel_analysis_interface.py
--- a/yt/utilities/parallel_tools/parallel_analysis_interface.py Mon Jan 24 21:10:49 2011 -0500
+++ b/yt/utilities/parallel_tools/parallel_analysis_interface.py Tue Jan 25 11:40:56 2011 -0500
@@ -62,8 +62,11 @@
if ytcfg.getboolean("yt","LogFile"):
ytcfg["yt","LogFile"] = "False"
yt.utilities.logger.disable_file_logging()
+ yt.utilities.logger.uncolorize_logging()
+ # Even though the uncolorize function already resets the format string,
+ # we reset it again so that it includes the processor.
f = logging.Formatter("P%03i %s" % (MPI.COMM_WORLD.rank,
- yt.utilities.logger.fstring))
+ yt.utilities.logger.ufstring))
yt.utilities.logger.rootLogger.handlers[0].setFormatter(f)
if ytcfg.getint("yt","LogLevel") < 20:
yt.utilities.logger.ytLogger.warning(
More information about the yt-svn
mailing list