From 1f543d7e7a95747d67cc0e41946f26e0e558095d Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 23 Apr 2024 08:59:42 -0700 Subject: [PATCH] Revert "wip: drop the file and keep the early-init logging" This reverts commit 3b1a1e3c12d203497accd7caf6be80a32effd95e. --- magic-nix-cache/src/api.rs | 6 ++++++ magic-nix-cache/src/main.rs | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/magic-nix-cache/src/api.rs b/magic-nix-cache/src/api.rs index ae643bd..e8d8919 100644 --- a/magic-nix-cache/src/api.rs +++ b/magic-nix-cache/src/api.rs @@ -57,6 +57,12 @@ async fn workflow_finish( } } + // NOTE(cole-h): see `init_logging` + let logfile = std::env::temp_dir().join("magic-nix-cache-tracing.log"); + let logfile_contents = std::fs::read_to_string(logfile)?; + println!("Every log line throughout the lifetime of the program:"); + println!("\n{logfile_contents}\n"); + let reply = WorkflowFinishResponse {}; //state.metrics.num_new_paths.set(num_new_paths); diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index 31cee73..f735ad0 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -447,7 +447,7 @@ async fn main() -> Result<()> { } } -fn init_logging() -> Result<()> { +fn init_logging() -> Result { let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| { #[cfg(debug_assertions)] return EnvFilter::new("info") @@ -462,12 +462,23 @@ fn init_logging() -> Result<()> { .with_writer(std::io::stderr) .pretty(); + let logfile = std::env::temp_dir().join("magic-nix-cache-tracing.log"); + let file = std::fs::OpenOptions::new() + .create(true) + .append(true) + .open(logfile)?; + let (nonblocking, guard) = tracing_appender::non_blocking(file); + let file_layer = tracing_subscriber::fmt::layer() + .with_writer(nonblocking) + .pretty(); + tracing_subscriber::registry() .with(filter) .with(stderr_layer) + .with(file_layer) .init(); - Ok(()) + Ok(guard) } #[cfg(debug_assertions)]