Created
December 12, 2014 20:13
-
-
Save tcotav/e7843df353c72e780934 to your computer and use it in GitHub Desktop.
python logging example
This file contains hidden or 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
| import time | |
| import logging | |
| from logging.handlers import TimedRotatingFileHandler | |
| loglvl = logging.DEBUG | |
| logname="py.log" | |
| logger=logging.getLogger(logname) | |
| logger.setLevel(loglvl) | |
| path="./%s" % logname | |
| # create file handler which logs even debug messages | |
| fh = TimedRotatingFileHandler(path, when="m", interval=1, backupCount=5) | |
| fh.setLevel(loglvl) | |
| formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
| fh.setFormatter(formatter) | |
| # add the handlers to the logger | |
| logger.addHandler(fh) | |
| if __name__ == "__main__": | |
| while True: | |
| logger.info("now") | |
| time.sleep(30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment