Created
May 16, 2016 10:03
-
-
Save yangdm0209/cc63a3e164e32b70d983d5658e7a9dcd to your computer and use it in GitHub Desktop.
Python logger wrap
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 | |
# coding: utf-8 | |
import logging.handlers | |
logger = logging.getLogger() | |
logger.setLevel(logging.DEBUG) | |
rht = logging.handlers.TimedRotatingFileHandler("reindex_out.log", 'D') | |
fmt = logging.Formatter("%(asctime)s %(pathname)s [%(levelname)s] %(funcName)s:%(lineno)d - %(message)s","%Y-%m-%d %H:%M:%S") | |
rht.setFormatter(fmt) | |
logger.addHandler(rht) | |
console = logging.StreamHandler() | |
console.setLevel(logging.DEBUG) | |
formatter = logging.Formatter('%(pathname)s [%(levelname)s] %(funcName)s:%(lineno)d - %(message)s') | |
console.setFormatter(formatter) | |
logger.addHandler(console) | |
debug = logger.debug | |
info = logger.info | |
warning = logger.warn | |
error = logger.error | |
critical = logger.critical |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment