import logging
from logging.handlers import RotatingFileHandler
rfh = RotatingFileHandler(
filename='resources/log.txt',
mode='a',
maxBytes=1000,
backupCount=5,
encoding=None,
delay=False
)
rfh.setFormatter(
logging.Formatter(('%(levelname)-8s / %(name)-8s / %(message)s'),'%d-%m-%Y %H:%M:%S')
)
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(name)-5s %(levelname)-8s %(message)s",
datefmt="%y-%m-%d %H:%M:%S"
)
logging.getLogger().addHandler(rfh)
logger = logging.getLogger('main')
for i in range(100):
logger.debug(i)
# For me the answer of "Clumsy Cassowary" didn't work. For everyone that
# has the problem as well try this answer.