Revert "wip: drop the file and keep the early-init logging"

This reverts commit 3b1a1e3c12.
This commit is contained in:
Cole Helbling 2024-04-23 08:59:42 -07:00
parent 5cb3d69802
commit 1f543d7e7a
2 changed files with 19 additions and 2 deletions

View file

@ -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);

View file

@ -447,7 +447,7 @@ async fn main() -> Result<()> {
}
}
fn init_logging() -> Result<()> {
fn init_logging() -> Result<tracing_appender::non_blocking::WorkerGuard> {
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)]