summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2023-12-27 10:20:01 +0100
committerSebastian Thiel <sebastian.thiel@icloud.com>2023-12-27 10:23:35 +0100
commit6fbe17ff51360d62086aa265a0baa9288175cb84 (patch)
tree2f21bab362c07efb96a206116a4bfb7bec6d740c /src
parent45d886a6b2c194a5a68961b428f8db2c8daf06a8 (diff)
feat: add `--log-file` flag to keep track of some debug info, which includes panics.
Previously, when `dua i` was used, panics would be hard to observe, if at all, as they would print to the alternate screen. Now, when the `--log-file dua.log` is specified, the panic will be emitted into the log file instead and thus won't be lost anymore. This may help with debugging in future.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs7
-rw-r--r--src/options.rs2
2 files changed, 4 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 42bb4f3..818d971 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,8 @@
#![forbid(unsafe_code, rust_2018_idioms, unsafe_code)]
use anyhow::Result;
-#[macro_use]
-extern crate log;
use clap::Parser;
use dua::TraversalSorting;
+use log::info;
use simplelog::{Config, LevelFilter, WriteLogger};
use std::fs::OpenOptions;
use std::{fs, io, io::Write, path::PathBuf, process};
@@ -27,6 +26,7 @@ fn main() -> Result<()> {
let opt: options::Args = options::Args::parse_from(wild::args_os());
if let Some(log_file) = &opt.log_file {
+ log_panics::init();
WriteLogger::init(
LevelFilter::Info,
Config::default(),
@@ -36,9 +36,8 @@ fn main() -> Result<()> {
.append(true)
.open(log_file)?,
)?;
+ info!("dua options={opt:#?}");
}
- info!("dua-cli has started");
- info!("opt={:#?}", opt);
let walk_options = dua::WalkOptions {
threads: opt.threads,
diff --git a/src/options.rs b/src/options.rs
index 60e0875..a59a90b 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -80,7 +80,7 @@ pub struct Args {
#[clap(value_parser)]
pub input: Vec<PathBuf>,
- /// If set, dua will log debug information to a file.
+ /// Write a log file with debug information, including panics.
#[clap(long)]
pub log_file: Option<PathBuf>,
}