Last active
March 21, 2019 03:30
-
-
Save yijia2413/15936a448953cc744570cff373b83fb5 to your computer and use it in GitHub Desktop.
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
logging.basicConfig(filename=logname, | |
filemode='a', | |
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', | |
datefmt='%H:%M:%S', | |
level=logging.DEBUG) | |
logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', | |
datefmt='%d-%m-%Y:%H:%M:%S', | |
level=logging.DEBUG) | |
formatter = logging.Formatter('[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s','%m-%d %H:%M:%S') | |
# set up logging to file | |
logging.basicConfig( | |
filename='twitter_effect.log', | |
level=logging.INFO, | |
format= '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', | |
datefmt='%H:%M:%S' | |
) | |
# set up logging to console | |
console = logging.StreamHandler() | |
console.setLevel(logging.DEBUG) | |
# set a format which is simpler for console use | |
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') | |
console.setFormatter(formatter) | |
# add the handler to the root logger | |
logging.getLogger('').addHandler(console) | |
logger = logging.getLogger(__name__) |
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
def setlogger(filename): | |
formatter = logging.Formatter('%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s') | |
handler = TimedRotatingFileHandler(filename, | |
when='midnight', | |
backupCount=10) | |
handler.setFormatter(formatter) | |
logger = logging.getLogger(__name__) | |
logger.addHandler(handler) | |
logger.setLevel(logging.INFO) | |
return logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment