Skip to content
Permalink
Browse files

Different approach -- two loggers

The logger that the 'debug' module logs on is now vistrails.logger. It
is internal and API users should NOT configure it (change level or
attach filters/handlers to it). It is controlled by the 'debug' module.

This internal logger re-logs to a 'vistrails' logger, which is meant to
be configured by API users if needed -- changing the level of this one
won't break anything.
  • Loading branch information...
remram44 committed Aug 27, 2014
1 parent 54e770a commit 0d6e56357a656e5d4b7547ab16de899d736be52c
Showing with 18 additions and 28 deletions.
  1. +18 −28 vistrails/core/debug.py
@@ -133,24 +133,16 @@ def emit(self, record):

################################################################################

class LevelCheckerLogger(logging.Logger):
def callHandlers(self, record):
"""Variant that checks the parents' levels when propagating.
"""
for hdlr in self.handlers:
if record.levelno >= hdlr.level:
hdlr.handle(record)
if (self.propagate and self.parent and
self.parent.isEnabledFor(record.levelno)):
c = self.parent
while c:
for hdlr in c.handlers:
if record.levelno >= hdlr.level:
hdlr.handle(record)
if not c.propagate:
c = None #break out
else:
c = c.parent
class LoggerHandler(logging.Logger):
"""A logging Handler Handler re-logs on a specified Logger.
"""
def __init__(self, logger):
logging.Handler.__init__(self)
self.logger = logger

def emit(self, record):
if self.logger.isEnabledFor(record.levelno):
self.logger.handle(record)

################################################################################

@@ -203,16 +195,8 @@ def make_logger(self, f=None):
We will configure log so it outputs to both stderr and a file.
"""
# Setup root logger
logging._acquireLock()
try:
oldLoggerClass = logging.getLoggerClass()
logging.setLoggerClass(LevelCheckerLogger)
self.logger = logging.getLogger('vistrails')
logging.setLoggerClass(oldLoggerClass)
finally:
logging._releaseLock()
assert isinstance(self.logger, LevelCheckerLogger)
# Internal logger, the one we log on
self.logger = logging.getLogger('vistrails.logger')

self.logger.setLevel(logging.DEBUG)
self.format = logging.Formatter("%(asctime)s %(levelname)s:\n%(message)s")
@@ -234,6 +218,12 @@ def make_logger(self, f=None):
self.console.setLevel(logging.WARNING)
self.logger.addHandler(self.console)

# We also propagate to a second logger, that API users might want to
# configure
self.visible_logger = logging.getLogger('vistrails')
self.logger.propagate = False
self.logger.addHandler(LoggerHandler(self.visible_logger))

# if system.python_version() <= (2,4,0,'',0):
# raise VersionTooLow('Python', '2.4.0')

0 comments on commit 0d6e563

Please sign in to comment.
You can’t perform that action at this time.