Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log files are massive. #63

Open
willwade opened this issue Nov 4, 2024 · 0 comments
Open

Log files are massive. #63

willwade opened this issue Nov 4, 2024 · 0 comments

Comments

@willwade
Copy link
Contributor

willwade commented Nov 4, 2024

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.cache_timer = None
        self.cache_cleaner = None
        self.pipe_thread = None
        self.tray_icon = None
        self.icon = QIcon("assets/translate.ico")
        self.icon_loading = QIcon("assets/translate_loading.ico")
        self.init_ui()
        self.init_pipe_server()
        self.init_cache_cleaner()
        self.init_log_cleaner()  # Initialize log cleaner with QTimer
        self.tray_icon.setToolTip("Waiting for new client...")

    def init_ui(self):
        self.tray_icon = SystemTrayIcon(self.icon, self)
        self.tray_icon.setVisible(True)

    def init_pipe_server(self):
        self.pipe_thread = PipeServerThread()
        self.pipe_thread.message_received.connect(self.handle_message)
        self.pipe_thread.start()

    def init_cache_cleaner(self):
        self.cache_cleaner = CacheCleanerThread()
        self.cache_timer = QTimer(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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant