Logs are getting auto deleted after the date is changed.
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Python logging.handlers.TimedRotatingFileHandler 的實作及其 rollover 行為開始,使用提供的午夜設定作為重現案例。檢查午夜之後的第一筆記錄如何被指派至輪替後的檔案名稱,以及 backupCount=1 如何刪除檔案。當前一天的日誌保持完整,且新一天的記錄寫入作用中的日誌檔案,並為此案例提供回歸測試涵蓋時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100