1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

on windows, log to C:\Users\USER\.local/share/wezterm/gui-log-PID.txt

refs: #1576
This commit is contained in:
Wez Furlong 2022-03-17 16:52:35 -07:00
parent 51e27acf1e
commit 27088fab28
2 changed files with 19 additions and 6 deletions

View File

@ -11,6 +11,7 @@ chrono = {version="0.4", features=["unstable-locales"]}
config = { path = "../config" }
dirs-next = "2.0"
lazy_static = "1.4"
libc = "0.2"
log = "0.4"
pretty_env_logger = "0.4"
@ -19,6 +20,5 @@ winapi = "0.3"
[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.20"
libc = "0.2"
objc = "0.2"

View File

@ -171,13 +171,26 @@ pub fn get_entries() -> Vec<Entry> {
fn setup_pretty() -> (LevelFilter, Option<Box<dyn log::Log>>) {
#[cfg(windows)]
{
use std::os::windows::io::IntoRawHandle;
use winapi::um::winbase::STD_ERROR_HANDLE;
// Working around <https://github.com/rust-lang/rust/issues/88576>
// wherein Rust 1.56 panics in the case that stderr is NULL.
// That can legitimately occur in a Windows subsystem executable.
// We detect that here and avoid initializing the pretty env logger.
// When launched as a GUI, stderr is null.
// Let's redirect it to a log file to aid in debugging.
if unsafe { winapi::um::processenv::GetStdHandle(STD_ERROR_HANDLE).is_null() } {
return (LevelFilter::Info, None);
let log_file_name =
config::RUNTIME_DIR.join(format!("gui-log-{}.txt", unsafe { libc::getpid() }));
if let Ok(file) = std::fs::OpenOptions::new()
.append(true)
.create(true)
.open(log_file_name)
{
let handle = file.into_raw_handle();
unsafe { winapi::um::processenv::SetStdHandle(STD_ERROR_HANDLE, handle) };
} else {
// If we fail to init a log file, skip setting up a logger to
// avoid a panic when built with 1.56
return (LevelFilter::Info, None);
}
}
}