Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Created May 13, 2021 04:19
Show Gist options
  • Save Abhayparashar31/8959b8afab3e5a7dc63582f638a180d0 to your computer and use it in GitHub Desktop.
Save Abhayparashar31/8959b8afab3e5a7dc63582f638a180d0 to your computer and use it in GitHub Desktop.
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