Replace print statements with proper logging

This commit is contained in:
Pavel Baksy 2026-01-05 11:46:15 +01:00
parent 60d4b32cd8
commit 4006ed7c34
5 changed files with 22 additions and 7 deletions

View File

@ -19,6 +19,7 @@
import json
import os
import logging
from pathlib import Path
from typing import List
import gi
@ -26,6 +27,8 @@ gi.require_version('GLib', '2.0')
from gi.repository import GLib
from .models import HistoryEntry
logger = logging.getLogger(__name__)
class HistoryManager:
"""Manages request history persistence to JSON file."""
@ -53,7 +56,7 @@ class HistoryManager:
return [HistoryEntry.from_dict(entry) for entry in data.get('entries', [])]
except Exception as e:
print(f"Error loading history: {e}")
logger.error(f"Error loading history: {e}")
return []
def save_history(self, entries: List[HistoryEntry]):
@ -67,7 +70,7 @@ class HistoryManager:
with open(self.history_file, 'w') as f:
json.dump(data, f, indent=2)
except Exception as e:
print(f"Error saving history: {e}")
logger.error(f"Error saving history: {e}")
def add_entry(self, entry: HistoryEntry):
"""Add new entry to history and save."""

View File

@ -19,6 +19,7 @@
import json
import uuid
import logging
from pathlib import Path
from typing import List, Optional
from datetime import datetime, timezone
@ -27,6 +28,8 @@ gi.require_version('GLib', '2.0')
from gi.repository import GLib
from .models import Project, SavedRequest, HttpRequest, Environment
logger = logging.getLogger(__name__)
class ProjectManager:
"""Manages project and saved request persistence."""
@ -53,7 +56,7 @@ class ProjectManager:
data = json.load(f)
return [Project.from_dict(p) for p in data.get('projects', [])]
except Exception as e:
print(f"Error loading projects: {e}")
logger.error(f"Error loading projects: {e}")
return []
def save_projects(self, projects: List[Project]):
@ -66,7 +69,7 @@ class ProjectManager:
with open(self.projects_file, 'w') as f:
json.dump(data, f, indent=2)
except Exception as e:
print(f"Error saving projects: {e}")
logger.error(f"Error saving projects: {e}")
def add_project(self, name: str) -> Project:
"""Create new project with default environment."""

View File

@ -21,11 +21,14 @@ import gi
gi.require_version('GtkSource', '5')
from gi.repository import Adw, Gtk, GLib, GtkSource, GObject
from typing import Optional, Set, Dict, List
import logging
from .models import HttpRequest, HttpResponse
from .widgets.header_row import HeaderRow
import json
import xml.dom.minidom
logger = logging.getLogger(__name__)
class RequestTabWidget(Gtk.Box):
"""Widget representing a single request tab's UI."""
@ -1125,7 +1128,7 @@ class RequestTabWidget(Gtk.Box):
dom = xml.dom.minidom.parseString(body)
return dom.toprettyxml(indent=" ")
except Exception as e:
print(f"Failed to format body: {e}")
logger.debug(f"Failed to format response body: {e}")
return body

View File

@ -20,10 +20,13 @@
from typing import List, Optional
import uuid
import json
import logging
from pathlib import Path
from .models import RequestTab, HttpRequest, HttpResponse
logger = logging.getLogger(__name__)
class TabManager:
"""Manages open request tabs."""
@ -147,6 +150,6 @@ class TabManager:
except (FileNotFoundError, json.JSONDecodeError, KeyError) as e:
# If session file is invalid, start fresh
print(f"Failed to load session: {e}")
logger.warning(f"Failed to load session: {e}")
self.tabs = []
self.active_tab_id = None

View File

@ -21,6 +21,7 @@ import gi
gi.require_version('GtkSource', '5')
from gi.repository import Adw, Gtk, GLib, Gio, GtkSource
from typing import Dict, Optional
import logging
from .models import HttpRequest, HttpResponse, HistoryEntry, RequestTab
from .http_client import HttpClient
from .history_manager import HistoryManager
@ -35,6 +36,8 @@ from datetime import datetime
import json
import uuid
logger = logging.getLogger(__name__)
@Gtk.Template(resource_path='/cz/vesp/roster/main-window.ui')
class RosterWindow(Adw.ApplicationWindow):
@ -493,7 +496,7 @@ class RosterWindow(Adw.ApplicationWindow):
substituted_request, undefined = VariableSubstitution.substitute_request(modified_request, env)
# Log undefined variables for debugging
if undefined:
print(f"Warning: Undefined variables in request: {', '.join(undefined)}")
logger.warning(f"Undefined variables in request: {', '.join(undefined)}")
# Disable send button during request
widget.send_button.set_sensitive(False)