Skip to content

Commit

Permalink
Add null log handler, since spotify.audiosink.gstreamer have started …
Browse files Browse the repository at this point in the history
…using logging
  • Loading branch information
jodal committed Mar 4, 2012
1 parent 2def37d commit a45d17c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spotify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,3 +33,5 @@ class SpotifyError(Exception):

from spotify._spotify import api_version
from spotify._spotify import connect


0 comments on commit a45d17c

Please sign in to comment.