Created
September 26, 2016 10:09
-
-
Save elnygren/d58d6f5af23e6126eb52bd2156438a21 to your computer and use it in GitHub Desktop.
Sane Python logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setting up python logging is a pain in the but | |
# ...until you found this gist. | |
import logging | |
from logging.config import dictConfig as LOGGING_CONFIG | |
LOG_LEVEL = logging.INFO | |
LOGGING_CONFIG({ | |
'version': 1, | |
'formatters': { | |
'f': {'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s'} | |
}, | |
'handlers': { | |
'h': {'class': 'logging.StreamHandler', | |
'formatter': 'f', | |
'level': LOG_LEVEL} | |
}, | |
'root': { | |
'handlers': ['h'], | |
'level': LOG_LEVEL, | |
}, | |
}) | |
# anywhere in your code | |
# import logger | |
logger = logging.getLogger() | |
logger.info('we are logging to stdout with a nice format like we should be') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment