Last active
August 29, 2015 14:04
-
-
Save smbanaie/942f6f5080148851c298 to your computer and use it in GitHub Desktop.
Python Useful Code Snippet
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
##Add File Logger | |
import logging | |
logger = logging.getLogger('myapp') | |
hdlr = logging.FileHandler('/var/tmp/myapp.log') | |
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') | |
hdlr.setFormatter(formatter) | |
logger.addHandler(hdlr) | |
logger.setLevel(logging.WARNING) | |
We can use this logger object now to write entries to the log file: | |
logger.error('We have a problem') | |
logger.info('While this is just chatty') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment