diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2023-12-27 10:28:41 +0100 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2023-12-27 10:28:41 +0100 |
commit | 196f0d62f32aacc2d393ef2929305a831a150520 (patch) | |
tree | 789f614fbcdf774458b4bc3fd1f5b9170adf7edc | |
parent | 0a0dfe65c4a7bd8851841edf488296966ba27bf0 (diff) | |
parent | 6fbe17ff51360d62086aa265a0baa9288175cb84 (diff) |
Merge branch 'logging'
-rw-r--r-- | Cargo.lock | 172 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/common.rs | 2 | ||||
-rw-r--r-- | src/interactive/app/bytevis.rs | 10 | ||||
-rw-r--r-- | src/interactive/app/eventloop.rs | 4 | ||||
-rw-r--r-- | src/interactive/widgets/help.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 20 | ||||
-rw-r--r-- | src/options.rs | 4 |
8 files changed, 210 insertions, 7 deletions
@@ -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" @@ -293,6 +332,15 @@ dependencies = [ ] [[package]] +name = "deranged" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +dependencies = [ + "powerfmt", +] + +[[package]] name = "diff" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -315,6 +363,8 @@ dependencies = [ "human_format", "itertools", "jwalk", + "log", + "log-panics", "num_cpus", "once_cell", "open", @@ -322,6 +372,7 @@ dependencies = [ "petgraph", "pretty_assertions", "ratatui", + "simplelog", "trash", "tui-react", "unicode-segmentation", @@ -375,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" @@ -533,6 +590,12 @@ dependencies = [ ] [[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] name = "jwalk" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -565,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" @@ -589,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" @@ -620,6 +702,15 @@ dependencies = [ ] [[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + +[[package]] name = "objc" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -629,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" @@ -703,6 +803,12 @@ dependencies = [ ] [[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] name = "pretty_assertions" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -785,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" @@ -847,6 +959,17 @@ dependencies = [ ] [[package]] +name = "simplelog" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acee08041c5de3d5048c8b3f6f13fafb3026b24ba43c6a695a0c76179b844369" +dependencies = [ + "log", + "termcolor", + "time", +] + +[[package]] name = "smallvec" version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -913,6 +1036,15 @@ dependencies = [ ] [[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] name = "thiserror" version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -933,6 +1065,37 @@ dependencies = [ ] [[package]] +name = "time" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +dependencies = [ + "deranged", + "itoa", + "libc", + "num_threads", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +dependencies = [ + "time-core", +] + +[[package]] name = "tinyvec" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1068,6 +1231,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -43,6 +43,9 @@ once_cell = "1.19" gix-glob = "0.14.1" 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/common.rs b/src/common.rs index 60f46ce..66e2277 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,6 +1,7 @@ use crate::crossdev; use crate::traverse::{EntryData, Tree, TreeIndex}; use byte_unit::{n_gb_bytes, n_gib_bytes, n_mb_bytes, n_mib_bytes, ByteUnit}; +use log::info; use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; @@ -177,6 +178,7 @@ type WalkDir = jwalk::WalkDirGeneric<((), Option<Result<std::fs::Metadata, jwalk impl WalkOptions { pub(crate) fn iter_from_path(&self, root: &Path, root_device_id: u64) -> WalkDir { + info!("root path={:?}", root); WalkDir::new(root) .follow_links(false) .sort(match self.sorting { diff --git a/src/interactive/app/bytevis.rs b/src/interactive/app/bytevis.rs index d767ed1..1d1bc33 100644 --- a/src/interactive/app/bytevis.rs +++ b/src/interactive/app/bytevis.rs @@ -34,7 +34,7 @@ impl ByteVisualization { } impl fmt::Display for DisplayByteVisualization { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { use ByteVisualization::*; let Self { format, percentage } = self; @@ -58,7 +58,11 @@ impl fmt::Display for DisplayByteVisualization { } impl DisplayByteVisualization { - fn make_bar(f: &mut fmt::Formatter, percentage: f32, length: usize) -> Result<(), fmt::Error> { + fn make_bar( + f: &mut fmt::Formatter<'_>, + percentage: f32, + length: usize, + ) -> Result<(), fmt::Error> { // Print the filled part of the bar let block_length = (length as f32 * percentage).floor() as usize; for _ in 0..block_length { @@ -90,7 +94,7 @@ impl DisplayByteVisualization { } Ok(()) } - fn make_percentage(f: &mut fmt::Formatter, percentage: f32) -> Result<(), fmt::Error> { + fn make_percentage(f: &mut fmt::Formatter<'_>, percentage: f32) -> Result<(), fmt::Error> { write!(f, " {:>5.01}% ", percentage * 100.0) } } diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs index 18e4bf7..36f60e0 100644 --- a/src/interactive/app/eventloop.rs +++ b/src/interactive/app/eventloop.rs @@ -235,7 +235,7 @@ impl AppState { } } - fn search_glob_pattern(&mut self, tree_view: &mut TreeView, glob_pattern: &str) { + fn search_glob_pattern(&mut self, tree_view: &mut TreeView<'_>, glob_pattern: &str) { use FocussedPane::*; match glob_search(tree_view.tree(), self.navigation.view_root, glob_pattern) { Ok(matches) if matches.is_empty() => { @@ -321,7 +321,7 @@ impl AppState { pub fn draw_window<B>( window: &mut MainWindow, - props: MainWindowProps, + props: MainWindowProps<'_>, terminal: &mut Terminal<B>, cursor: &mut Cursor, ) -> Result<()> diff --git a/src/interactive/widgets/help.rs b/src/interactive/widgets/help.rs index 52948da..8ca2661 100644 --- a/src/interactive/widgets/help.rs +++ b/src/interactive/widgets/help.rs @@ -61,7 +61,7 @@ impl HelpPane { pub fn render(&mut self, props: impl Borrow<HelpPaneProps>, area: Rect, buf: &mut Buffer) { let lines = { - let lines = RefCell::new(Vec::<Line>::with_capacity(30)); + let lines = RefCell::new(Vec::<Line<'_>>::with_capacity(30)); let add_newlines = |n| { for _ in 0..n { lines.borrow_mut().push(Line::from(Span::raw(""))) diff --git a/src/main.rs b/src/main.rs index 47be1f0..818d971 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,10 @@ -#![forbid(unsafe_code)] +#![forbid(unsafe_code, rust_2018_idioms, unsafe_code)] use anyhow::Result; 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}; mod crossdev; @@ -21,6 +24,21 @@ fn main() -> Result<()> { use options::Command::*; 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(), + OpenOptions::new() + .write(true) + .create(true) + .append(true) + .open(log_file)?, + )?; + info!("dua options={opt:#?}"); + } + let walk_options = dua::WalkOptions { threads: opt.threads, byte_format: opt.format.into(), diff --git a/src/options.rs b/src/options.rs index 13705b3..a59a90b 100644 --- a/src/options.rs +++ b/src/options.rs @@ -79,6 +79,10 @@ pub struct Args { /// One or more input files or directories. If unset, we will use all entries in the current working directory. #[clap(value_parser)] pub input: Vec<PathBuf>, + + /// Write a log file with debug information, including panics. + #[clap(long)] + pub log_file: Option<PathBuf>, } #[derive(Debug, clap::Subcommand)] |