summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--Cargo.lock80
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs7
-rw-r--r--src/options.rs2
4 files changed, 85 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8034bf5..399800f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,21 @@
version = 3
[[package]]
+name = "addr2line"
+version = "0.21.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
+dependencies = [
+ "gimli",
+]
+
+[[package]]
+name = "adler"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
+
+[[package]]
name = "ahash"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -92,6 +107,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
+name = "backtrace"
+version = "0.3.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
+dependencies = [
+ "addr2line",
+ "cc",
+ "cfg-if",
+ "libc",
+ "miniz_oxide",
+ "object",
+ "rustc-demangle",
+]
+
+[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -131,6 +161,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
[[package]]
+name = "cc"
+version = "1.0.83"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -325,6 +364,7 @@ dependencies = [
"itertools",
"jwalk",
"log",
+ "log-panics",
"num_cpus",
"once_cell",
"open",
@@ -386,6 +426,12 @@ dependencies = [
]
[[package]]
+name = "gimli"
+version = "0.28.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
+
+[[package]]
name = "gix-features"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -582,6 +628,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
+name = "log-panics"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68f9dd8546191c1850ecf67d22f5ff00a935b890d0e84713159a55495cc2ac5f"
+dependencies = [
+ "backtrace",
+ "log",
+]
+
+[[package]]
name = "lru"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -606,6 +662,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
+name = "miniz_oxide"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
+dependencies = [
+ "adler",
+]
+
+[[package]]
name = "mio"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -655,6 +720,15 @@ dependencies = [
]
[[package]]
+name = "object"
+version = "0.32.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -817,6 +891,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
[[package]]
+name = "rustc-demangle"
+version = "0.1.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
+
+[[package]]
name = "rustversion"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 5a1a000..54ef47e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -45,6 +45,7 @@ gix-path = "0.10.1"
bstr = "1.8.0"
simplelog = "0.12.1"
log = "0.4.20"
+log-panics = { version = "2", features = ["with-backtrace"]}
[[bin]]
name="dua"
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>,
}