File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change
1
+ import logging
1
2
import os
2
3
import sys
3
- import logging
4
- from typing import Optional , List
5
4
from datetime import datetime
5
+ from logging .handlers import RotatingFileHandler
6
+ from typing import List , Optional
6
7
7
8
from . import dirs
8
9
from .decorators import deprecated
@@ -100,7 +101,13 @@ def _create_file_handler(
100
101
log_name = name + "_" + ("testing_" if testing else "" ) + now_str + file_ext
101
102
log_file_path = os .path .join (log_dir , log_name )
102
103
103
- fh = logging .FileHandler (log_file_path , mode = "w" )
104
+ # Create rotating logfile handler, max 10MB per file, 3 files max
105
+ # Prevents logfile from growing too large, like in:
106
+ # - https://github.com/ActivityWatch/activitywatch/issues/815#issue-1423555466
107
+ # - https://github.com/ActivityWatch/activitywatch/issues/756#issuecomment-1266662861
108
+ fh = RotatingFileHandler (
109
+ log_file_path , mode = "a" , maxBytes = 10 * 1024 * 1024 , backupCount = 3
110
+ )
104
111
if log_json :
105
112
fh .setFormatter (_create_json_formatter ())
106
113
else :
You can’t perform that action at this time.
0 commit comments