Skip to content

Instantly share code, notes, and snippets.

@tadeck
Created April 21, 2013 00:42
Show Gist options
  • Save tadeck/5427998 to your computer and use it in GitHub Desktop.
Save tadeck/5427998 to your computer and use it in GitHub Desktop.
The snippet adding support for logging even if code using it does not add handlers to module's logger. Shamelessly copied from python-requests.
# Set default logging handler to avoid "No handler found" warnings.
import logging
try: # Python 2.7+
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
logging.getLogger(__name__).addHandler(NullHandler())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment