Logs are getting auto deleted after the date is changed.
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với phần triển khai Python logging.handlers.TimedRotatingFileHandler và hành vi rollover của nó, sử dụng cấu hình nửa đêm được cung cấp làm trường hợp tái hiện. Kiểm tra cách bản ghi đầu tiên sau nửa đêm được gán vào tên tệp đã xoay vòng và cách backupCount=1 xóa các tệp. Được xem là hoàn tất khi các log của ngày trước vẫn nguyên vẹn và các bản ghi của ngày mới được ghi vào tệp log đang hoạt động, với kiểm thử hồi quy cho trường hợp này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100