Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ at `warn`. `<PREFIX>_LOG=info` or `debug` works as before (that level for the ap
errors from the rest; any other value: warnings and errors only) and wins over `RUST_LOG`, which otherwise replaces
the default with env_logger-style directives such as `RUST_LOG=debug` or `RUST_LOG=warn,lcc_pipeline=trace` (a
directive ending in `*` covers every target starting with it, as in `lcc*=debug`). Panics are recorded there
too, and still in `<binary>-panics.log` in the temp folder. The logger is `apps/app/src/logging.rs`.
too, and in `<binary>-panics.log` beside the log files. The logger is `apps/app/src/logging.rs`.

The web build needs the `wasm32-unknown-unknown` target and the matching `wasm-bindgen` CLI
(`cargo xtask web` prints the exact install command); see [docs/web.md](docs/web.md).
Expand Down
2 changes: 1 addition & 1 deletion README.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ at `warn`. `<PREFIX>_LOG=info` or `debug` works as before (that level for the ap
errors from the rest; any other value: warnings and errors only) and wins over `RUST_LOG`, which otherwise replaces
the default with env_logger-style directives such as `RUST_LOG=debug` or `RUST_LOG=warn,lcc_pipeline=trace` (a
directive ending in `*` covers every target starting with it, as in `lcc*=debug`). Panics are recorded there
too, and still in `<binary>-panics.log` in the temp folder. The logger is `apps/app/src/logging.rs`.
too, and in `<binary>-panics.log` beside the log files. The logger is `apps/app/src/logging.rs`.

The web build needs the `wasm32-unknown-unknown` target and the matching `wasm-bindgen` CLI
(`cargo xtask web` prints the exact install command); see [docs/web.md](docs/web.md).
Expand Down
2 changes: 1 addition & 1 deletion apps/android/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn main(activity: AndroidApp) {
config_root: config_root.clone(),
pictures: external.unwrap_or_else(|| config_root.clone()),
});
lcc_engine::guard::install_hook(config_root.join(format!("{}-panics.log", lcc_brand::BINARY)));
lcc_engine::guard::install_hook(Some(config_root.join(format!("{}-panics.log", lcc_brand::BINARY))));

let host = match Host::new(&activity) {
Ok(h) => Some(Arc::new(h)),
Expand Down
28 changes: 11 additions & 17 deletions apps/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,20 +1068,18 @@ fn publish_control_token(port: u16, token: &str, supplied: bool) {
}
}

/// An isolated profile keeps the emergency crash log with its other app data. With no
/// override (or an empty override), retain the historical system-temp location.
fn panic_log_path_with(env: impl Fn(&str) -> Option<std::ffi::OsString>, temp: std::path::PathBuf) -> std::path::PathBuf {
env("CONFIG_DIR")
.filter(|value| !value.is_empty())
.map(std::path::PathBuf::from)
.unwrap_or(temp)
.join(format!("{}-panics.log", lcc_brand::BINARY))
/// The emergency crash log, `<binary>-panics.log` beside the other logs in the user's own settings
/// folder (an isolated profile's with `<PREFIX>_CONFIG_DIR`). Never the shared temp folder, where
/// another user on the machine could create the file first or point it at one of the user's files.
/// `None` (standard error only) where no logs are kept.
fn panic_log_path() -> Option<std::path::PathBuf> {
log_dir().map(|d| d.join(format!("{}-panics.log", lcc_brand::BINARY)))
}

fn main() -> eframe::Result {
// First, so every start-up record is kept for the log file (`logging`).
let logger = logging::install();
lcc_engine::guard::install_hook(panic_log_path_with(lcc_brand::env_os, std::env::temp_dir()));
lcc_engine::guard::install_hook(panic_log_path());
if let Some(logger) = logger {
logging::record_panics(logger);
}
Expand Down Expand Up @@ -2100,14 +2098,10 @@ mod tests {
mod config_path_tests {
use super::*;

/// The panic log sits beside the other logs in the settings folder, never in the temp folder.
#[test]
fn config_override_keeps_panic_log_in_isolated_profile() {
let temp = std::path::PathBuf::from("temp");
assert_eq!(
panic_log_path_with(|_| Some("isolated".into()), temp.clone()),
std::path::PathBuf::from("isolated").join(format!("{}-panics.log", lcc_brand::BINARY))
);
assert_eq!(panic_log_path_with(|_| None, temp.clone()), temp.join(format!("{}-panics.log", lcc_brand::BINARY)));
assert_eq!(panic_log_path_with(|_| Some("".into()), temp.clone()), temp.join(format!("{}-panics.log", lcc_brand::BINARY)));
fn panic_log_stays_in_the_settings_folder() {
let name = format!("{}-panics.log", lcc_brand::BINARY);
assert_eq!(panic_log_path(), log_dir().map(|d| d.join(name)));
}
}
11 changes: 8 additions & 3 deletions crates/engine/src/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ pub fn catch<T>(what: &str, f: impl FnOnce() -> T) -> Result<T, String> {
}

/// Install a panic hook that keeps the default report (stderr) and also appends the panic's
/// location and message to `log` (best effort), so a panic in a GUI session leaves a trace.
pub fn install_hook(log: PathBuf) {
/// location and message to `log` (best effort, its folder made when missing; `None` writes nothing),
/// so a panic in a GUI session leaves a trace. `log` belongs in a folder of the user's own.
pub fn install_hook(log: Option<PathBuf>) {
let default = panic::take_hook();
panic::set_hook(Box::new(move |info| {
default(info);
let at = info.location().map(|l| format!("{}:{}", l.file(), l.line())).unwrap_or_default();
let secs = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);
let thread = std::thread::current().name().unwrap_or("unnamed").to_string();
if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(&log) {
let Some(log) = &log else { return };
if let Some(dir) = log.parent() {
let _ = std::fs::create_dir_all(dir);
}
if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(log) {
let _ = writeln!(f, "{secs} [{thread}] panic at {at}: {}", panic_message(info.payload()));
}
}));
Expand Down
2 changes: 2 additions & 0 deletions docs/whats-new/2026-10-31-panic-log-settings-folder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Panic log moves to the settings folder
- The emergency panic log is now written beside the other log files in your settings folder instead of the shared temp folder, so another user on the machine can no longer pre-create it or point it at one of your files.