diff --git a/docs/changes.rst b/docs/changes.rst index 869d551b..2d34763e 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -41,6 +41,15 @@ v1.7 (in development) - Added optional argument ``type`` for :class:`spotify.ArtistBrowser`. +- pyspotify now registers a "null handler" for logging to the ``spotify`` + logger. This means that any pyspotify code is free to log debug log to any + logger matching ``spotify.*``. + + By default the log statements will be swallowed by the null handler. An + application developer using pyspotify may add an additional log handler which + listens for log messages to the ``spotify`` logger, and thus get debug + information from pyspotify. + - Bundled audio sink support: - A audio sink wrapper for `PortAudio diff --git a/spotify/__init__.py b/spotify/__init__.py index f1ee2755..9eb5aa45 100644 --- a/spotify/__init__.py +++ b/spotify/__init__.py @@ -3,6 +3,20 @@ class SpotifyError(Exception): pass +# pylint: disable = W0404 +def _add_null_handler_for_logging(): + import logging + try: + NullHandler = logging.NullHandler # Python 2.7 and upwards + except AttributeError: + class NullHandler(logging.Handler): + def emit(self, record): + pass + logging.getLogger('spotify').addHandler(NullHandler()) + +_add_null_handler_for_logging() +# pylint: enable = W0404 + from spotify._spotify import Session from spotify._spotify import Track from spotify._spotify import Artist @@ -19,3 +33,5 @@ class SpotifyError(Exception): from spotify._spotify import api_version from spotify._spotify import connect + +