[PR #5147] [MERGED] feat(agent): file-based logs with rotation #5077

Closed
opened 2026-03-17 02:33:33 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5147
Author: @CuriousCorrelation
Created: 6/13/2025
Status: Merged
Merged: 6/13/2025
Merged by: @AndrewBastin

Base: patchHead: feat-agent-file-based-rotating-logs


📝 Commits (1)

  • 59337da feat(agent): file-based logs with rotation

📊 Changes

8 files changed (+122 additions, -64 deletions)

View changed files

📝 packages/hoppscotch-agent/src-tauri/Cargo.lock (+13 -1)
📝 packages/hoppscotch-agent/src-tauri/Cargo.toml (+2 -0)
📝 packages/hoppscotch-agent/src-tauri/src/error.rs (+7 -1)
📝 packages/hoppscotch-agent/src-tauri/src/lib.rs (+4 -48)
packages/hoppscotch-agent/src-tauri/src/logger.rs (+53 -0)
📝 packages/hoppscotch-agent/src-tauri/src/main.rs (+38 -8)
📝 packages/hoppscotch-agent/src-tauri/src/tray.rs (+3 -4)
📝 packages/hoppscotch-desktop/src-tauri/src/logger.rs (+2 -2)

📄 Description

This adds a file-based logging system with size-based rotation to the Hoppscotch Agent.

It essentially redirects existing diagnostic to size-based rotating files for troubleshooting environment-specific issues.

Closes HFE-897

Agent currently lacks a persistent logging mechanism in production environments. Logs are only available through the development mode console. Mainly aiming to understand errors in specific environments that can't be reproduced in our testing setups.

This implementation uses the tracing ecosystem (tracing, tracing_subscriber, tracing_appender) along with file_rotate to create log files in the platform's log directory.

The logs are automatically rotated when they reach 10MB, with a maximum of 5 files retained.

Thinking 10 * 5 MB just like the desktop app is reasonable disk usage while maintaining sufficient history.

The system currently writes to both the console (with ANSI colors where supported) and to files (without ANSI formatting for readability).

Log levels in dev mode are currently controlled via the RUST_LOG environment variable, defaulting to "debug" when not specified.

OS Log File Path
Windows C:\Users\<username>\AppData\Local\io.hoppscotch.agent\logs\io.hoppscotch.agent.log
macOS ~/Library/Logs/io.hoppscotch.agent/io.hoppscotch.agent.log
Linux ~/.local/share/io.hoppscotch.agent/logs/io.hoppscotch.agent.log

Notes to reviewers

About setting up logging in main

Moved setup_logging function from lib.rs to its own module in logger.rs to make sure it starts up before any plugins are initialized, which means we can control when the global default trace dispatcher is setup. Logger setup call in lib.rs (where it used to be commented out) would actually setup two dispatcher, eventually failing with panic:

a global default trace dispatcher has already been set
thread 'main' panicked at library/core/src/panicking.rs:218:5:
panic in a function that cannot unwind

The current setup avoids that and also lets the logger collect startup logs.

Testing

We need to make sure:

  1. The agent functions normally
  2. Logs are present in platform's respective directories, i.e. ~/Library/Logs/io.hoppscotch.agent/io.hoppscotch.agent.log on MacOS
  3. Logs are collected correctly
Library/Logs/io.hoppscotch.agent
❯ head -14 io.hoppscotch.agent.log
2025-06-12T11:17:29.434256Z  INFO main ThreadId(01) hoppscotch_agent_lib::logger: Logging initialized with rotating file log_file=/Users/curiouscorrelation/Library/Logs/io.hoppscotch.agent/io.hoppscotch.agent.log
2025-06-12T11:17:29.434797Z  INFO main ThreadId(01) hoppscotch_agent: Starting Hoppscotch Agent...
2025-06-12T11:17:29.434882Z  INFO main ThreadId(01) hoppscotch_agent_lib: Initializing Hoppscotch Agent
2025-06-12T11:17:29.435113Z DEBUG main ThreadId(01) hoppscotch_agent_lib: Building Tauri application
2025-06-12T11:17:29.436135Z  INFO main ThreadId(01) hoppscotch_agent_lib: Building Tauri application with context
2025-06-12T11:17:29.485082Z  INFO main ThreadId(01) hoppscotch_agent_lib: Running application
2025-06-12T11:17:29.512823Z  INFO main ThreadId(01) hoppscotch_agent_lib: Setting up application
2025-06-12T11:17:29.512875Z DEBUG main ThreadId(01) hoppscotch_agent_lib: Configuring autostart for desktop variant
2025-06-12T11:17:29.513158Z  INFO main ThreadId(01) hoppscotch_agent_lib: Checking autostart status enabled=true
2025-06-12T11:17:29.513183Z DEBUG main ThreadId(01) hoppscotch_agent_lib: Initializing desktop-specific features
2025-06-12T11:17:29.513825Z  INFO main ThreadId(01) create_main_window: hoppscotch_agent_lib: Creating main application window
2025-06-12T11:17:29.513973Z DEBUG main ThreadId(01) create_main_window: hoppscotch_agent_lib: Building webview window from config
2025-06-12T11:17:29.514304Z DEBUG tokio-runtime-worker ThreadId(14) tauri_plugin_updater::updater: checking for updates https://releases.hoppscotch.com/hoppscotch-agent.json
2025-06-12T11:17:29.515975Z DEBUG tokio-runtime-worker ThreadId(14) reqwest::connect: starting new connection: https://releases.hoppscotch.com/

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5147 **Author:** [@CuriousCorrelation](https://github.com/CuriousCorrelation) **Created:** 6/13/2025 **Status:** ✅ Merged **Merged:** 6/13/2025 **Merged by:** [@AndrewBastin](https://github.com/AndrewBastin) **Base:** `patch` ← **Head:** `feat-agent-file-based-rotating-logs` --- ### 📝 Commits (1) - [`59337da`](https://github.com/hoppscotch/hoppscotch/commit/59337da96cec41668c4b171518a831596ee6f586) feat(agent): file-based logs with rotation ### 📊 Changes **8 files changed** (+122 additions, -64 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-agent/src-tauri/Cargo.lock` (+13 -1) 📝 `packages/hoppscotch-agent/src-tauri/Cargo.toml` (+2 -0) 📝 `packages/hoppscotch-agent/src-tauri/src/error.rs` (+7 -1) 📝 `packages/hoppscotch-agent/src-tauri/src/lib.rs` (+4 -48) ➕ `packages/hoppscotch-agent/src-tauri/src/logger.rs` (+53 -0) 📝 `packages/hoppscotch-agent/src-tauri/src/main.rs` (+38 -8) 📝 `packages/hoppscotch-agent/src-tauri/src/tray.rs` (+3 -4) 📝 `packages/hoppscotch-desktop/src-tauri/src/logger.rs` (+2 -2) </details> ### 📄 Description This adds a file-based logging system with size-based rotation to the Hoppscotch Agent. It essentially redirects existing diagnostic to size-based rotating files for troubleshooting environment-specific issues. Closes HFE-897 Agent currently lacks a persistent logging mechanism in production environments. Logs are only available through the development mode console. Mainly aiming to understand errors in specific environments that can't be reproduced in our testing setups. This implementation uses the tracing ecosystem (`tracing`, `tracing_subscriber`, `tracing_appender`) along with `file_rotate` to create log files in the platform's log directory. The logs are automatically rotated when they reach 10MB, with a maximum of 5 files retained. Thinking `10 * 5 MB` just like the desktop app is reasonable disk usage while maintaining sufficient history. The system currently writes to both the console (with ANSI colors where supported) and to files (without ANSI formatting for readability). Log levels in `dev` mode are currently controlled via the `RUST_LOG` environment variable, defaulting to "debug" when not specified. | OS | Log File Path | |---|---| | Windows | `C:\Users\<username>\AppData\Local\io.hoppscotch.agent\logs\io.hoppscotch.agent.log` | | macOS | `~/Library/Logs/io.hoppscotch.agent/io.hoppscotch.agent.log` | | Linux | `~/.local/share/io.hoppscotch.agent/logs/io.hoppscotch.agent.log` | ### Notes to reviewers #### About setting up logging in `main` Moved `setup_logging` function from `lib.rs` to its own module in `logger.rs` to make sure it starts up before any plugins are initialized, which means we can control when the global default trace dispatcher is setup. Logger setup call in `lib.rs` (where it used to be commented out) would actually setup two dispatcher, eventually failing with panic: ``` a global default trace dispatcher has already been set thread 'main' panicked at library/core/src/panicking.rs:218:5: panic in a function that cannot unwind ``` The current setup avoids that and also lets the logger collect startup logs. #### Testing We need to make sure: 1. The agent functions normally 2. Logs are present in platform's respective directories, i.e. `~/Library/Logs/io.hoppscotch.agent/io.hoppscotch.agent.log` on MacOS 3. Logs are collected correctly ``` Library/Logs/io.hoppscotch.agent ❯ head -14 io.hoppscotch.agent.log 2025-06-12T11:17:29.434256Z INFO main ThreadId(01) hoppscotch_agent_lib::logger: Logging initialized with rotating file log_file=/Users/curiouscorrelation/Library/Logs/io.hoppscotch.agent/io.hoppscotch.agent.log 2025-06-12T11:17:29.434797Z INFO main ThreadId(01) hoppscotch_agent: Starting Hoppscotch Agent... 2025-06-12T11:17:29.434882Z INFO main ThreadId(01) hoppscotch_agent_lib: Initializing Hoppscotch Agent 2025-06-12T11:17:29.435113Z DEBUG main ThreadId(01) hoppscotch_agent_lib: Building Tauri application 2025-06-12T11:17:29.436135Z INFO main ThreadId(01) hoppscotch_agent_lib: Building Tauri application with context 2025-06-12T11:17:29.485082Z INFO main ThreadId(01) hoppscotch_agent_lib: Running application 2025-06-12T11:17:29.512823Z INFO main ThreadId(01) hoppscotch_agent_lib: Setting up application 2025-06-12T11:17:29.512875Z DEBUG main ThreadId(01) hoppscotch_agent_lib: Configuring autostart for desktop variant 2025-06-12T11:17:29.513158Z INFO main ThreadId(01) hoppscotch_agent_lib: Checking autostart status enabled=true 2025-06-12T11:17:29.513183Z DEBUG main ThreadId(01) hoppscotch_agent_lib: Initializing desktop-specific features 2025-06-12T11:17:29.513825Z INFO main ThreadId(01) create_main_window: hoppscotch_agent_lib: Creating main application window 2025-06-12T11:17:29.513973Z DEBUG main ThreadId(01) create_main_window: hoppscotch_agent_lib: Building webview window from config 2025-06-12T11:17:29.514304Z DEBUG tokio-runtime-worker ThreadId(14) tauri_plugin_updater::updater: checking for updates https://releases.hoppscotch.com/hoppscotch-agent.json 2025-06-12T11:17:29.515975Z DEBUG tokio-runtime-worker ThreadId(14) reqwest::connect: starting new connection: https://releases.hoppscotch.com/ ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:33:33 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5077
No description provided.