Created
May 13, 2021 04:19
-
-
Save Abhayparashar31/8959b8afab3e5a7dc63582f638a180d0 to your computer and use it in GitHub Desktop.
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 logging | |
| from logging.handlers import RotatingFileHandler | |
| logger = logging.getLogger(__name__) | |
| logger.setLevel(logging.INFO) | |
| # roll over after 2KB, and keep backup logs app.log.1, app.log.2 , etc. | |
| handler = RotatingFileHandler('app.log', maxBytes=2000, backupCount=5) | |
| logger.addHandler(handler) | |
| for i in range(10000): | |
| logger.info(i) | |
| ------------------------------------OUTPUT------------------------ | |
| YOu will see five files app.log.1, app.log.2 and so on. Files contains the recent log report. Everyfile starts from the end of previous file. | |
| For Example: app.log - 9843-9999 | |
| app.log.1 - 9510-9842 | |
| app.log.2 - 9177 -9509 | |
| .... | |
| .... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment