Add network logging to Discord webhook for testing branch

- Add network_logging.py module with Discord webhook integration
- Log session start with unique session ID and mode (MOCK/PRODUCTION)
- Log all page navigations when clicking Next
- Log all user selections (disk, install mode, modules, user info)
- Log installation progress through each step
- Send install completion/failure logs
- Auto-flush logs every 2 seconds and immediately on critical events

TESTING BRANCH ONLY - Remove before merging to main
This commit is contained in:
2026-02-04 21:18:18 +01:00
parent e611f174be
commit f7bebc7f88
5 changed files with 430 additions and 87 deletions

View File

@@ -1,6 +1,8 @@
import gi
import threading
import logging
import uuid
from datetime import datetime
gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")
@@ -13,6 +15,7 @@ from .pages.storage import StoragePage
from .pages.summary import SummaryPage
from .pages.user import UserPage
from .pages.welcome import WelcomePage
from ..backend.network_logging import log_to_discord, flush_logs
class LogHandler(logging.Handler):
@@ -30,6 +33,15 @@ class InstallerWindow(Adw.ApplicationWindow):
super().__init__(*args, **kwargs)
self.mock_mode = mock_mode
self.session_id = str(uuid.uuid4())[:8]
# Send session start ping
mode_str = "MOCK" if mock_mode else "PRODUCTION"
log_to_discord(
"SESSION_START",
f"Iridium Installer started - Session: {self.session_id} - Mode: {mode_str}",
"installer",
)
self.set_default_size(900, 650)
self.set_title("Iridium Installer" + (" (MOCK MODE)" if mock_mode else ""))
@@ -102,7 +114,7 @@ class InstallerWindow(Adw.ApplicationWindow):
if self.page_ids:
self.stack.set_visible_child_name(self.page_ids[0])
self.update_buttons()
self.log_handler = None
def add_page(self, widget, name):
@@ -163,27 +175,27 @@ class InstallerWindow(Adw.ApplicationWindow):
prog_page = Adw.StatusPage()
prog_page.set_title(message)
prog_page.set_description("Please wait while we set up your system.")
spinner = Gtk.Spinner()
spinner.set_size_request(32, 32)
spinner.set_halign(Gtk.Align.CENTER)
spinner.start()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
box.append(spinner)
# Log view
self.log_buffer = Gtk.TextBuffer()
self.log_view = Gtk.TextView(buffer=self.log_buffer)
self.log_view.set_editable(False)
self.log_view.set_monospace(True)
self.log_view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
scrolled = Gtk.ScrolledWindow()
scrolled.set_child(self.log_view)
scrolled.set_vexpand(True)
scrolled.set_size_request(-1, 200)
# Style the log view background
# css_provider = Gtk.CssProvider()
# css_provider.load_from_data(b"textview { background-color: #1e1e1e; color: #ffffff; }")
@@ -194,14 +206,14 @@ class InstallerWindow(Adw.ApplicationWindow):
box.append(expander)
prog_page.set_child(box)
name = "progress_install"
self.stack.add_named(prog_page, name)
self.stack.set_visible_child_name(name)
# Hide navigation buttons during install
self.bottom_bar.set_visible(False)
# Attach log handler
self.log_handler = LogHandler(self.append_log)
logging.getLogger().addHandler(self.log_handler)
@@ -229,14 +241,14 @@ class InstallerWindow(Adw.ApplicationWindow):
finish_page.set_icon_name("dialog-error-symbolic")
finish_page.set_description("An error occurred during installation.")
btn_label = "Close"
btn = Gtk.Button(label=btn_label)
btn.set_halign(Gtk.Align.CENTER)
btn.add_css_class("suggested-action")
btn.connect("clicked", lambda b: self.close())
finish_page.set_child(btn)
name = "finish_install"
self.stack.add_named(finish_page, name)
self.stack.set_visible_child_name(name)
@@ -245,43 +257,122 @@ class InstallerWindow(Adw.ApplicationWindow):
try:
from ..backend.disk import auto_partition_disk, mount_partitions
from ..backend.os_install import install_minimal_os, configure_system
from ..backend.network_logging import log_to_discord as nlog
# Step 1: Partitioning
logging.info("Step 1: Partitioning...")
nlog(
"INSTALL_PROGRESS",
f"Session: {self.session_id} - Starting partitioning on {disk}",
"installer",
)
parts = auto_partition_disk(disk)
nlog(
"INSTALL_PROGRESS",
f"Session: {self.session_id} - Partitioning complete",
"installer",
)
# Step 2: Mounting
logging.info("Step 2: Mounting...")
nlog(
"INSTALL_PROGRESS",
f"Session: {self.session_id} - Mounting partitions",
"installer",
)
mount_root = "/mnt"
mount_partitions(parts, mount_root)
nlog(
"INSTALL_PROGRESS",
f"Session: {self.session_id} - Mounting complete",
"installer",
)
# Step 3: OS Installation
logging.info("Step 3: OS Installation...")
nlog(
"INSTALL_PROGRESS",
f"Session: {self.session_id} - Installing OS (this may take a while)",
"installer",
)
install_minimal_os(mount_root)
nlog(
"INSTALL_PROGRESS",
f"Session: {self.session_id} - OS installation complete",
"installer",
)
# Step 4: Configure
logging.info("Step 4: Configuration...")
nlog(
"INSTALL_PROGRESS",
f"Session: {self.session_id} - Configuring bootloader",
"installer",
)
configure_system(mount_root, parts)
nlog(
"INSTALL_PROGRESS",
f"Session: {self.session_id} - Bootloader configuration complete",
"installer",
)
# Install complete
nlog(
"INSTALL_COMPLETE",
f"Session: {self.session_id} - Installation completed successfully!",
"installer",
)
flush_logs()
GLib.idle_add(self.show_finish_page, "Installation Successful!", True)
except Exception as e:
error_msg = str(e)
logging.error(f"Installation failed: {e}")
nlog(
"INSTALL_ERROR",
f"Session: {self.session_id} - Installation failed: {error_msg}",
"installer",
)
import traceback
traceback.print_exc()
nlog(
"INSTALL_ERROR",
f"Session: {self.session_id} - Traceback: {traceback.format_exc()}",
"installer",
)
flush_logs()
GLib.idle_add(self.show_finish_page, f"Installation Failed: {e}", False)
def on_next_clicked(self, button):
# Logic before transition
# Log navigation
current_page_name = self.page_ids[self.current_page_index]
mode_str = "MOCK" if self.mock_mode else "PRODUCTION"
log_to_discord(
"NAVIGATION_NEXT",
f"Session: {self.session_id} - Page: {current_page_name} - Mode: {mode_str}",
"installer",
)
# Logic before transition
if current_page_name == "storage":
selected_disk = self.storage_page.get_selected_disk()
log_to_discord(
"SELECTION",
f"Session: {self.session_id} - Selected disk: {selected_disk}",
"installer",
)
self.partitioning_page.load_partitions(selected_disk)
next_index = self.current_page_index + 1
if current_page_name == "install_mode":
mode = self.install_mode_page.get_mode()
log_to_discord(
"SELECTION",
f"Session: {self.session_id} - Install mode: {mode}",
"installer",
)
if mode == "automatic":
# Skip partitioning page
next_index = self.page_ids.index("modules")
@@ -289,6 +380,14 @@ class InstallerWindow(Adw.ApplicationWindow):
# Go to partitioning page
next_index = self.page_ids.index("partitioning")
if current_page_name == "modules":
modules = self.modules_page.get_modules()
log_to_discord(
"SELECTION",
f"Session: {self.session_id} - Selected modules: {modules}",
"installer",
)
if current_page_name == "user":
# Prepare summary instead of installing immediately
disk = self.storage_page.get_selected_disk()
@@ -296,6 +395,13 @@ class InstallerWindow(Adw.ApplicationWindow):
modules = self.modules_page.get_modules()
user_info = self.user_page.get_user_info()
# Log user info (without password for security)
log_to_discord(
"SELECTION",
f"Session: {self.session_id} - User: {user_info.get('username', 'N/A')}, Hostname: {user_info.get('hostname', 'N/A')}, Sudo: {user_info.get('allow_sudo', False)}",
"installer",
)
partitions_config = {}
if mode == "manual":
partitions_config = self.partitioning_page.get_config()
@@ -321,6 +427,13 @@ class InstallerWindow(Adw.ApplicationWindow):
modules = self.modules_page.get_modules()
user_info = self.user_page.get_user_info()
# Log the install trigger with full config
log_to_discord(
"INSTALL_START",
f"Session: {self.session_id} - Disk: {disk} - Mode: {mode} - Modules: {modules} - Mock: {self.mock_mode}",
"installer",
)
if self.mock_mode:
print("!!! MOCK MODE ENABLED - NO CHANGES WILL BE MADE !!!")
print(f"Target Disk: {disk}")
@@ -328,6 +441,12 @@ class InstallerWindow(Adw.ApplicationWindow):
print(f"Modules: {modules}")
print(f"User: {user_info}")
print("Simulation complete.")
log_to_discord(
"INSTALL_COMPLETE",
f"Session: {self.session_id} - Mock installation complete",
"installer",
)
flush_logs()
# Show success in UI even in mock
self.show_finish_page("Mock Installation Complete!")
else:
@@ -335,7 +454,7 @@ class InstallerWindow(Adw.ApplicationWindow):
thread = threading.Thread(
target=self.run_installation,
args=(disk, mode, modules, user_info),
daemon=True
daemon=True,
)
thread.start()
@@ -344,4 +463,4 @@ class InstallerWindow(Adw.ApplicationWindow):
if next_index < len(self.page_ids):
self.current_page_index = next_index
self.stack.set_visible_child_name(self.page_ids[self.current_page_index])
self.update_buttons()
self.update_buttons()