Skip to content

Instantly share code, notes, and snippets.

@123Daoxyz
Created August 14, 2016 12:45
Show Gist options
  • Save 123Daoxyz/a733cb415f22d8d13b75fd691bda0bfe to your computer and use it in GitHub Desktop.
Save 123Daoxyz/a733cb415f22d8d13b75fd691bda0bfe to your computer and use it in GitHub Desktop.
python logging snippets
#!/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