Skip to content

Commit 55866d0

Browse files
committed
FileLogger handler use RotatingFileHandler
1 parent c66d5c4 commit 55866d0

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

prime_backup/utils/log_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import contextlib
22
import logging
3+
from logging.handlers import RotatingFileHandler
34
from pathlib import Path
45
from typing import Generator
56

@@ -15,7 +16,12 @@ def __init__(self, name: str):
1516
super().__init__(f'{constants.PLUGIN_ID}-{name}', get_log_level())
1617
self.log_file = self.__get_log_file_path(f'{name}.log')
1718
self.log_file.parent.mkdir(parents=True, exist_ok=True)
18-
handler = logging.FileHandler(self.log_file, encoding='utf8')
19+
handler = RotatingFileHandler(
20+
self.log_file,
21+
maxBytes=10 * 1024 * 1024,
22+
backupCount=1,
23+
encoding='utf8'
24+
)
1925
handler.setFormatter(LOG_FORMATTER)
2026
self.addHandler(handler)
2127

0 commit comments

Comments
 (0)