Mercurial > code > home > repos > light9
changeset 2176:e1233a04dc2d
don't fight with pytest logger
author | drewp@bigasterisk.com |
---|---|
date | Fri, 19 May 2023 14:40:13 -0700 |
parents | 28bcd763303c |
children | 9036ebf37b04 |
files | light9/run_local.py |
diffstat | 1 files changed, 15 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/run_local.py Fri May 19 14:38:56 2023 -0700 +++ b/light9/run_local.py Fri May 19 14:40:13 2023 -0700 @@ -38,21 +38,24 @@ 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']: