Logs are getting auto deleted after the date is changed.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
I have written a code that would rotate logs on midnight maintaing backup of 1 day. But the next day, the previous logs are getting deleted.
For example :
While I am checking logs on 14th Feb, I noticed that all the logs generated on 13th Feb, got deleted from instancelogs.log.2025-02-13. The first log generated on 14th Feb is getting stored in instancelogs.log.2025-02-13 file instead of instancelogs.log file , the remaining logs for 14th Feb are correctly stored in instancelogs.log file.
Please look into the issue as we are losing all the logs for 13th of Feb.
I am using below code to handle logs:
import logging
from logging.handlers import TimedRotatingFileHandler
#logger instances for PPT creator
LOG_FILE_PATH = "../STORE_LOGS/instancelogs.log"
instance_logger = logging.getLogger('instance_logger')
instance_logger_file_handler = None
instance_logger_file_handler = TimedRotatingFileHandler(LOG_FILE_PATH, when='midnight', interval=1, backupCount=1)
instance_logger_file_formatter = logging.Formatter(
fmt="[%(asctime)s] - [%(levelname)s] - [%(filename)s] - [%(funcName)s] - %(message)s",
datefmt="%d-%m-%y %H:%M:%S")
instance_logger_file_handler.setFormatter(instance_logger_file_formatter)
instance_logger.setLevel(logging.DEBUG)
instance_logger.addHandler(instance_logger_file_handler)
CPython versions tested on:
3.9
Operating systems tested on:
Linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Python logging.handlers.TimedRotatingFileHandler implementation and its rollover behavior, using the provided midnight configuration as a reproduction case. Check how the first record after midnight is assigned to the rotated filename and how backupCount=1 removes files. Done means the prior day's logs remain intact and new-day records go to the active log file, with regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100