# HG changeset patch # User drewp@bigasterisk.com # Date 2023-05-19 21:40:13 # Node ID e1233a04dc2db661da0b6ee1ebcf7cd0094694fa # Parent 28bcd763303c3be62f32115fce3219b29cf6304e don't fight with pytest logger diff --git a/light9/run_local.py b/light9/run_local.py --- a/light9/run_local.py +++ b/light9/run_local.py @@ -38,21 +38,24 @@ log = logging.getLogger() # this has to log.name = progName # but we can rename it for clarity -class FractionTimeFilter(logging.Filter): +def fracTimeLogger(): + class FractionTimeFilter(logging.Filter): - def filter(self, record): - record.fractionTime = ( - time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(record.created)) + - ("%.3f" % (record.created % 1)).lstrip('0')) - # Don't filter the record. - return 1 + def filter(self, record): + record.fractionTime = ( + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(record.created)) + + ("%.3f" % (record.created % 1)).lstrip('0')) + # Don't filter the record. + return 1 + coloredlogs.install( + level='DEBUG', + fmt='%(fractionTime)s %(name)s[%(process)d] %(levelname)s %(message)s') + logging.getLogger().handlers[0].addFilter(FractionTimeFilter()) -coloredlogs.install( - level='DEBUG', - fmt='%(fractionTime)s %(name)s[%(process)d] %(levelname)s %(message)s') -logging.getLogger().handlers[0].addFilter(FractionTimeFilter()) - +# pytest's log replacement would try to use our fmt with fractionTime but not our handler that supports it. See https://github.com/pytest-dev/pytest/issues/2987 +if 'pytest' not in sys.modules: + fracTimeLogger() def setTerminalTitle(s): if os.environ.get('TERM', '') in ['xterm', 'rxvt', 'rxvt-unicode-256color']: