diff --git a/CHANGELOG.md b/CHANGELOG.md index ee96be80..b7e6e468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * fix: avoid sending mouse click events on pane frames to applications (https://github.com/zellij-org/zellij/pull/1584) * feat: search through terminal scrollback (https://github.com/zellij-org/zellij/pull/1521) * feat: support themes directory (https://github.com/zellij-org/zellij/pull/1577) +* feat: Improve logging by writing server panics into the logfile (https://github.com/zellij-org/zellij/pull/1602) ## [0.30.0] - 2022-06-07 * fix: right and middle clicks creating selection (https://github.com/zellij-org/zellij/pull/1372) diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 3b81694b..380b39c8 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -7,7 +7,6 @@ mod sessions; mod stdin_ansi_parser; mod stdin_handler; -use log::error; use log::info; use std::env::current_exe; use std::io::{self, Write}; @@ -210,7 +209,6 @@ pub fn start_client( let send_client_instructions = send_client_instructions.clone(); let os_input = os_input.clone(); Box::new(move |info| { - error!("Panic occurred in client:\n{:?}", info); if let Ok(()) = os_input.unset_raw_mode(0) { handle_panic(info, &send_client_instructions); } diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index 0e18bb9e..bd206122 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -3,6 +3,7 @@ use crate::channels::{SenderWithContext, ASYNCOPENCALLS, OPENCALLS}; use colored::*; +use log::error; use serde::{Deserialize, Serialize}; use std::fmt::{Display, Error, Formatter}; use std::panic::PanicInfo; @@ -70,13 +71,15 @@ where let mut report: Report = Panic(format!("\u{1b}[0;31m{}\u{1b}[0;0m", msg)).into(); + let mut location_string = String::new(); if let Some(location) = info.location() { - report = report.wrap_err(format!( + location_string = format!( "At {}:{}:{}", location.file(), location.line(), location.column() - )); + ); + report = report.wrap_err(location_string.clone()); } if !err_ctx.is_empty() { @@ -88,6 +91,17 @@ where thread )); + error!( + "{}", + format!( + "Panic occured: + thread: {} + location: {} + message: {}", + thread, location_string, msg + ) + ); + if thread == "main" { // here we only show the first line because the backtrace is not readable otherwise // a better solution would be to escape raw mode before we do this, but it's not trivial