Created
August 14, 2016 12:45
-
-
Save 123Daoxyz/a733cb415f22d8d13b75fd691bda0bfe to your computer and use it in GitHub Desktop.
python logging snippets
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
#!/usr/bin/env python | |
# encoding: utf-8 | |
import logging | |
import sys | |
FMT = ( | |
'[%(levelname)s][%(name)s:%(process)d][%(asctime)s]' + | |
': %(message)s') | |
def init(name): | |
log = logging.getLogger(name) | |
log.setLevel(logging.DEBUG) | |
# create console handler and set level to debug | |
ch = logging.StreamHandler(sys.stdout) | |
ch.setLevel(logging.DEBUG) | |
fmt = logging.Formatter(FMT) | |
ch.setFormatter(fmt) | |
log.addHandler(ch) | |
return log | |
log = init('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment