diff options
| author | Sakarias Johansson <sakarias.johansson@goodbyekansas.com> | 2023-04-16 14:52:03 +0200 |
|---|---|---|
| committer | Sakarias Johansson <sakariasjohansson@hotmail.com> | 2023-04-16 15:03:31 +0200 |
| commit | 53af9befcc76054471459d216a2ab2d11e81150e (patch) | |
| tree | 0897c33266c6f09dda4972746381c8a5602f6b55 /racer-tracer | |
| parent | c7cbd0d288083ad7ae132ac6627cf93ec5b3aed5 (diff) | |
| download | racer-tracer-53af9befcc76054471459d216a2ab2d11e81150e.tar.gz racer-tracer-53af9befcc76054471459d216a2ab2d11e81150e.tar.xz racer-tracer-53af9befcc76054471459d216a2ab2d11e81150e.zip | |
🐛 Fix bug where logs would not flush
Slog has a problem where if the logs are created in the same scope as
std::process::exit is called it will not be able to flush the logs.
Moved log creation to another method. The main function does barely
anything now.
Diffstat (limited to 'racer-tracer')
| -rw-r--r-- | racer-tracer/src/main.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/racer-tracer/src/main.rs b/racer-tracer/src/main.rs index 16fe6c4..7069b56 100644 --- a/racer-tracer/src/main.rs +++ b/racer-tracer/src/main.rs @@ -166,22 +166,33 @@ fn create_log(log_file: &Path) -> Result<Logger, TracerError> { }) } -fn main() { +// There is a problem with slog where if the log is created in the +// same scope as where a process::exit is called it won't flush +// correctly before exiting. +fn bridge_main(config: Config) -> i32 { let log_file = std::env::temp_dir().join("racer-tracer.log"); let log = create_log(log_file.as_ref()).expect("Expected to be able to create a log"); let term = Terminal::new(log.new(o!("scope" => "terminal"))); terminal::write_term!(term, &format!("Log file: {}", log_file.display())); - match Config::try_from(Args::from_args()) - .and_then(|config| run(config, log.new(o!("scope" => "run")), term)) - { - Err(TracerError::ExitEvent) => {} - Ok(_) => {} + match run(config, log.new(o!("scope" => "run")), term) { + Err(TracerError::ExitEvent) => 0, + Ok(_) => 0, Err(e) => { error!(log, "Error: {}", e); let exit_code = i32::from(e); error!(log, "Exiting with: {}", exit_code); - std::process::exit(exit_code) + exit_code + } + } +} + +fn main() { + match Config::try_from(Args::from_args()).map(bridge_main) { + Ok(ec) => std::process::exit(ec), + Err(e) => { + println!("Failed to parse config file: {}", e); + std::process::exit(0) } } } |
