Skip to content

Commit

Permalink
Add log cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
willwade authored Nov 4, 2024
1 parent 3f7a83a commit 2d46a09
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions AACSpeakHelperServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def __init__(self):
self.init_ui()
self.init_pipe_server()
self.init_cache_cleaner()
self.init_log_cleaner()
self.tray_icon.setToolTip("Waiting for new client...")

def init_ui(self):
Expand All @@ -185,6 +186,23 @@ def init_cache_cleaner(self):
self.cache_timer.timeout.connect(lambda: self.cache_cleaner.start())
self.cache_timer.start(24 * 60 * 60 * 1000) # Run once a day

def init_log_cleaner(self):
self.log_timer = QTimer(self)
self.log_timer.timeout.connect(self.check_log_size)
self.log_timer.start(3600000) # Check every hour, adjust as needed

def check_log_size(self):
log_file = logfile
size_limit_mb = 1 # Size limit in MB
size_limit_bytes = size_limit_mb * 1024 * 1024 # Convert MB to bytes

try:
if os.path.isfile(log_file) and os.path.getsize(log_file) > size_limit_bytes:
with open(log_file, "w"): # Truncate the log file
logging.info("Log file exceeded size limit; log file truncated.")
except Exception as e:
logging.error(f"Error cleaning log file: {e}", exc_info=True)

@Slot(str)
def handle_message(self, message):
try:
Expand Down

0 comments on commit 2d46a09

Please sign in to comment.