mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 01:06:00 +03:00
[PR #5044] [MERGED] feat(desktop): complete lifecycle logs #5026
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5026
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5044
Author: @CuriousCorrelation
Created: 5/2/2025
Status: ✅ Merged
Merged: 5/21/2025
Merged by: @AndrewBastin
Base:
next← Head:feat-desktop-complete-logs📝 Commits (1)
a0f112ffeat(desktop): complete lifecycle logs📊 Changes
5 files changed (+91 additions, -18 deletions)
View changed files
📝
packages/hoppscotch-desktop/src-tauri/Cargo.lock(+39 -6)📝
packages/hoppscotch-desktop/src-tauri/Cargo.toml(+1 -0)📝
packages/hoppscotch-desktop/src-tauri/src/lib.rs(+1 -3)📝
packages/hoppscotch-desktop/src-tauri/src/logger.rs(+8 -8)📝
packages/hoppscotch-desktop/src-tauri/src/main.rs(+42 -1)📄 Description
This changes how logging is initialized and managed, fixing an issue where some logs were missing from
io.hoppscotch.logfiles.Closes HFE-838
Basically some debug log messages just weren't appearing in the logs. This was quite odd because other debug messages from the same module were appearing correctly.
In Tauri app, logging is tricky... mainly because of the application lifecycle. The application starts in
main.rsbefore any Tauri-specific functionality is available. Having log sinks setup atmainwould be great, but we also need file-based logging that requires the Tauri AppHandle to determine the right log file paths.There is a "theoretical" way to achieve this, to simply initialize logging twice:
Why this doesn't work is
tracingneeds a global dispatcherThis error occurs because the
tracingecosystem only allows setting the global default subscriber once, see:https://docs.rs/tracing-subscriber/latest/src/tracing_subscriber/util.rs.html#63-92
The issue is that when we use
init()to initialize the global dispatcher inmain.rs, we can't set it again inlib.rs. This means any early logs in the application lifecycle before the TauriAppHandleis available were getting captured by the basic console logger, but we couldn't add file-based logging later.The missing logs showed up when running the application with only the basic console logger set in
main.rs, but this approach lacks the file persistence based logging. Essentially we can see the disk space check and other initialization logs in the console, but they weren't being saved to the log file.A classic timing issue: we need file-based logging set up before Tauri plugins begin initialization but we could only get the appropriate paths after Tauri starts.
The solution is - rather than relying on Tauri's built-in path resolution which are only available after the app is created, we implemented a similar path resolution directly in
main.rs:This mimics Tauri's own path resolution logic to find the log directory before the Tauri application starts.
Next, change
logger.rsto accept a path rather than anAppHandle:So now, instead of managing the log guard within the
setupfunction usingapp_handle.manage(), we return the guard to the caller, allowing it to be managed in themainfunction's scope:The
_guardis important. Underscore is just for warnings, but the variable itself keeps the guard alive for the lifetime of themain. Since the guard is responsible for buffered logs to get flushed to disk.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.