From a3eb4602aa5ec87e6f78477c4789ed2fbde1cf93 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 28 Aug 2013 11:30:20 -0400 Subject: [PATCH] Update null log handling for py26 Python 2.6 does not have a NullHandler in the logging module, so introduce a little class that does the same work. Also add __all__ to the package init so extra names are not exported. Resolves issue #2 Change-Id: Id59d394cd02372e2c31de336894f06653cb1e22d --- stevedore/__init__.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/stevedore/__init__.py b/stevedore/__init__.py index 6e8f23b..93a56b2 100644 --- a/stevedore/__init__.py +++ b/stevedore/__init__.py @@ -1,5 +1,13 @@ # flake8: noqa +__all__ = [ + 'ExtensionManager', + 'EnabledExtensionManager', + 'NamedExtensionManager', + 'HookManager', + 'DriverManager', +] + from .extension import ExtensionManager from .enabled import EnabledExtensionManager from .named import NamedExtensionManager @@ -10,9 +18,19 @@ import logging # Configure a NullHandler for our log messages in case # the app we're used from does not set up logging. -LOG = logging.getLogger(__name__) -try: +LOG = logging.getLogger('stevedore') + +if hasattr(logging, 'NullHandler'): LOG.addHandler(logging.NullHandler()) -except AttributeError: - # No NullHandler, probably python 2.6 - pass +else: + class NullHandler(logging.Handler): + def handle(self, record): + pass + + def emit(self, record): + pass + + def createLock(self): + self.lock = None + + LOG.addHandler(NullHandler())