Created
June 2, 2018 03:10
-
-
Save ranjanashish/a4f147ced057595b7b8eaede00365ed4 to your computer and use it in GitHub Desktop.
log_config.py
This file contains hidden or 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
import logging | |
def setup_logging(level: str) -> None: | |
assert level in ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), f"Invalid log level: '{level}'" | |
logging.basicConfig( | |
level=getattr(logging, level), | |
format='%(asctime)s %(name)-30s %(lineno)5d %(levelname)-8s %(message)s', | |
datefmt='%Y-%m-%d %H:%M:%S', | |
stream=sys.stdout, | |
) | |
# suppress loggers in 3rd party libs | |
loggers = ( | |
# requests loggers | |
'requests', | |
'urllib3', | |
# celery loggers | |
'celery', | |
'kombu', | |
'amqp', | |
# boto3 loggers | |
'boto3', | |
'botocore', | |
) | |
for logger in loggers: | |
logging.getLogger(logger).setLevel(logging.ERROR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment