diff options
author | Daniel Watkins <oddbloke@ubuntu.com> | 2020-04-23 16:34:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-23 16:34:45 -0400 |
commit | c5b44e46c13b0940a30073dc36196e430f8d2acb (patch) | |
tree | 730c16cb57903557dceb61212ade810bca0b832a | |
parent | e9ab1235eb3944ede588188592a1aa1aaae02591 (diff) | |
download | vyos-cloud-init-c5b44e46c13b0940a30073dc36196e430f8d2acb.tar.gz vyos-cloud-init-c5b44e46c13b0940a30073dc36196e430f8d2acb.zip |
log: remove unnecessary import fallback logic (#327)
logging.NullHandler has been present since Python 3.1, we don't need to
handle its absence.
-rw-r--r-- | cloudinit/log.py | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/cloudinit/log.py b/cloudinit/log.py index 827db12b..2e5df042 100644 --- a/cloudinit/log.py +++ b/cloudinit/log.py @@ -122,17 +122,12 @@ def getLogger(name='cloudinit'): return logging.getLogger(name) -# Fixes this annoyance... -# No handlers could be found for logger XXX annoying output... -try: - from logging import NullHandler -except ImportError: - class NullHandler(logging.Handler): - def emit(self, record): - pass - - def _resetLogger(log): + """Remove all current handlers, unset log level and add a NullHandler. + + (Adding the NullHandler avoids "No handlers could be found for logger XXX" + messages.) + """ if not log: return handlers = list(log.handlers) @@ -141,7 +136,7 @@ def _resetLogger(log): h.close() log.removeHandler(h) log.setLevel(NOTSET) - log.addHandler(NullHandler()) + log.addHandler(logging.NullHandler()) def resetLogging(): |