commit 249035cf3338a10ba1e7e311cb650f10fcbbcb60 Author: Damian Johnson atagar@torproject.org Date: Sat Dec 31 13:34:46 2011 -0800
Moving null-handler logging hack into log util
Without a handler the builtin logging class emits a warning. To get around this I added a no-op handler if none already existed before any logging was done via a module import hack. However, now that we're using a log util we can put the hack in that instead.
I tried to repro the warning but didn't have any success... maybe the issue only exists for older python versions? Reguardless, this workaround doesn't do any harm so keeping it around. --- stem/__init__.py | 2 -- stem/util/__init__.py | 14 -------------- stem/util/log.py | 10 ++++++++++ 3 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/stem/__init__.py b/stem/__init__.py index 5b2cdd0..542c82d 100644 --- a/stem/__init__.py +++ b/stem/__init__.py @@ -2,7 +2,5 @@ Library for working with the tor process. """
-import stem.util # suppresses log handler warnings - __all__ = ["connection", "process", "socket", "version"]
diff --git a/stem/util/__init__.py b/stem/util/__init__.py index 14692fe..2e6b479 100644 --- a/stem/util/__init__.py +++ b/stem/util/__init__.py @@ -2,19 +2,5 @@ Utility functions used by the stem library. """
-# Adds a default nullhandler for the stem logger, suppressing the 'No handlers -# could be found for logger "stem"' warning as per... -# http://docs.python.org/release/3.1.3/library/logging.html#configuring-loggin... - -import logging - -class NullHandler(logging.Handler): - def emit(self, record): pass - -stem_logger = logging.getLogger("stem") - -if not stem_logger.handlers: - stem_logger.addHandler(NullHandler()) - __all__ = ["conf", "enum", "log", "proc", "system", "term"]
diff --git a/stem/util/log.py b/stem/util/log.py index 6476a67..7ab7895 100644 --- a/stem/util/log.py +++ b/stem/util/log.py @@ -37,6 +37,16 @@ LOG_VALUES = {
LOGGER = logging.getLogger("stem")
+# Adds a default nullhandler for the stem logger, suppressing the 'No handlers +# could be found for logger "stem"' warning as per... +# http://docs.python.org/release/3.1.3/library/logging.html#configuring-loggin... + +class NullHandler(logging.Handler): + def emit(self, record): pass + +if not LOGGER.handlers: + LOGGER.addHandler(NullHandler()) + def get_logger(): """ Provides the stem logger.