From dffc925bb6bb11a8d771d1f481a19d509389c84e Mon Sep 17 00:00:00 2001 From: claudi Date: Wed, 18 Feb 2026 13:19:38 +0100 Subject: [PATCH] refactor: Change logging level from info to debug for download and JS messages --- src/webdrop_bridge/ui/main_window.py | 50 +++++++++----------- src/webdrop_bridge/ui/restricted_web_view.py | 14 +++--- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/webdrop_bridge/ui/main_window.py b/src/webdrop_bridge/ui/main_window.py index fbfc1b3..dd1bf0d 100644 --- a/src/webdrop_bridge/ui/main_window.py +++ b/src/webdrop_bridge/ui/main_window.py @@ -238,7 +238,7 @@ class _DragBridge(QObject): Args: message: Debug message from JavaScript """ - logger.info(f"JS Debug: {message}") + logger.debug(f"JS Debug: {message}") class MainWindow(QMainWindow): @@ -327,7 +327,7 @@ class MainWindow(QMainWindow): # Set up download handler profile = self.web_view.page().profile() - logger.info(f"Connecting download handler to profile: {profile}") + logger.debug(f"Connecting download handler to profile: {profile}") # CRITICAL: Connect download handler BEFORE any page loads profile.downloadRequested.connect(self._on_download_requested) @@ -338,9 +338,9 @@ class MainWindow(QMainWindow): ) if downloads_path: profile.setDownloadPath(downloads_path) - logger.info(f"Download path set to: {downloads_path}") + logger.debug(f"Download path set to: {downloads_path}") - logger.info("Download handler connected successfully") + logger.debug("Download handler connected successfully") # Set up central widget with layout central_widget = QWidget() @@ -820,17 +820,13 @@ class MainWindow(QMainWindow): Args: download: Download request from the web engine """ - logger.info("=" * 60) - logger.info("🔥 DOWNLOAD REQUESTED - Handler called!") - logger.info("=" * 60) - try: - # Log all download details for debugging - logger.info(f"Download URL: {download.url().toString()}") - logger.info(f"Download filename: {download.downloadFileName()}") - logger.info(f"Download mime type: {download.mimeType()}") - logger.info(f"Download suggested filename: {download.suggestedFileName()}") - logger.info(f"Download state: {download.state()}") + # Log download details for debugging + logger.debug(f"Download URL: {download.url().toString()}") + logger.debug(f"Download filename: {download.downloadFileName()}") + logger.debug(f"Download mime type: {download.mimeType()}") + logger.debug(f"Download suggested filename: {download.suggestedFileName()}") + logger.debug(f"Download state: {download.state()}") # Get the system's Downloads folder downloads_path = QStandardPaths.writableLocation( @@ -850,14 +846,14 @@ class MainWindow(QMainWindow): # Construct full download path download_file = Path(downloads_path) / filename - logger.info(f"📁 Download will be saved to: {download_file}") + logger.debug(f"Download will be saved to: {download_file}") # Set download path and accept download.setDownloadDirectory(str(download_file.parent)) download.setDownloadFileName(download_file.name) download.accept() - logger.info(f"✅ Download accepted and started: {download_file}") + logger.info(f"Download started: {filename}") # Update status bar (temporarily) self.status_bar.showMessage( @@ -866,7 +862,7 @@ class MainWindow(QMainWindow): # Connect to state changed for progress tracking download.stateChanged.connect( - lambda state: logger.info(f"Download state changed to: {state}") + lambda state: logger.debug(f"Download state changed to: {state}") ) # Connect to finished signal for completion feedback @@ -875,8 +871,8 @@ class MainWindow(QMainWindow): ) except Exception as e: - logger.error(f"❌ Error handling download: {e}", exc_info=True) - self.status_bar.showMessage(f"❌ Download-Fehler: {e}", 5000) + logger.error(f"Error handling download: {e}", exc_info=True) + self.status_bar.showMessage(f"Download error: {e}", 5000) def _on_download_finished(self, download: QWebEngineDownloadRequest, file_path: Path) -> None: """Handle download completion. @@ -890,12 +886,12 @@ class MainWindow(QMainWindow): return state = download.state() - logger.info(f"Download finished with state: {state}") + logger.debug(f"Download finished with state: {state}") if state == QWebEngineDownloadRequest.DownloadState.DownloadCompleted: - logger.info(f"Download completed successfully: {file_path}") + logger.info(f"Download completed: {file_path.name}") self.status_bar.showMessage( - f"✅ Download abgeschlossen: {file_path.name}", 5000 + f"Download completed: {file_path.name}", 5000 ) elif state == QWebEngineDownloadRequest.DownloadState.DownloadCancelled: logger.info(f"Download cancelled: {file_path.name}") @@ -959,7 +955,7 @@ class MainWindow(QMainWindow): # Map JS log levels to Python log levels using enum if level == QWebEnginePage.JavaScriptConsoleMessageLevel.InfoMessageLevel: - logger.info(f"JS Console: {message}") + logger.debug(f"JS Console: {message}") elif level == QWebEnginePage.JavaScriptConsoleMessageLevel.WarningMessageLevel: logger.warning(f"JS Console: {message}") logger.debug(f" at {source_id}:{line_number}") @@ -982,11 +978,11 @@ class MainWindow(QMainWindow): # Check if bridge script is loaded def check_script(result): if result: - logger.info("✓ WebDrop Bridge script is active") - logger.info("✓ QWebChannel bridge is ready") + logger.debug("WebDrop Bridge script is active") + logger.debug("QWebChannel bridge is ready") else: - logger.error("✗ WebDrop Bridge script NOT loaded!") - logger.error(" Drag-and-drop conversion will NOT work") + logger.error("WebDrop Bridge script NOT loaded!") + logger.error("Drag-and-drop conversion will not work") # Execute JS to check if our script is loaded self.web_view.page().runJavaScript( diff --git a/src/webdrop_bridge/ui/restricted_web_view.py b/src/webdrop_bridge/ui/restricted_web_view.py index 7f20ad2..bd77741 100644 --- a/src/webdrop_bridge/ui/restricted_web_view.py +++ b/src/webdrop_bridge/ui/restricted_web_view.py @@ -74,7 +74,7 @@ class CustomWebEnginePage(QWebEnginePage): ] if any(url_str.lower().endswith(ext) for ext in download_extensions): - logger.info(f"🔽 Detected potential download URL: {url_str}") + logger.debug(f"Detected potential download URL: {url_str}") # This will trigger downloadRequested if it's a download return super().acceptNavigationRequest(url, nav_type, is_main_frame) @@ -90,13 +90,13 @@ class CustomWebEnginePage(QWebEnginePage): Returns: New page instance for the window """ - logger.info(f"🪟 New window requested, type: {window_type}") + logger.debug(f"New window requested, type: {window_type}") # Create a temporary page to handle the download # This page will never be displayed but allows downloads to work download_page = QWebEnginePage(self.profile(), self) - logger.info("✅ Created temporary page for download/popup") + logger.debug("Created temporary page for download/popup") # Return the temporary page - it will trigger downloadRequested if it's a download return download_page @@ -127,7 +127,7 @@ class RestrictedWebEngineView(QWebEngineView): custom_page = CustomWebEnginePage(self.profile, self) self.setPage(custom_page) - logger.info( + logger.debug( "RestrictedWebEngineView initialized with CustomWebEnginePage and persistent profile" ) @@ -170,9 +170,9 @@ class RestrictedWebEngineView(QWebEngineView): # Set cache size to 100 MB profile.setHttpCacheMaximumSize(100 * 1024 * 1024) - logger.info(f"Created persistent profile at: {profile_path}") - logger.info("Cookies policy: ForcePersistentCookies") - logger.info("HTTP cache: DiskHttpCache (100 MB)") + logger.debug(f"Created persistent profile at: {profile_path}") + logger.debug("Cookies policy: ForcePersistentCookies") + logger.debug("HTTP cache: DiskHttpCache (100 MB)") return profile