bin: Improve logging

This commit is contained in:
Erik Kundt
2024-07-19 13:29:36 +02:00
parent ee6da33bb4
commit bbad0a3081
7 changed files with 188 additions and 40 deletions
Generated
+133 -26
View File
@@ -948,6 +948,18 @@ dependencies = [
"digest",
]
[[package]]
name = "homedir"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bed305c13ce3829a09d627f5d43ff738482a09361ae4eb8039993b55fb10e5e"
dependencies = [
"cfg-if",
"nix 0.26.4",
"widestring",
"windows 0.57.0",
]
[[package]]
name = "iana-time-zone"
version = "0.1.57"
@@ -959,7 +971,7 @@ dependencies = [
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows",
"windows 0.48.0",
]
[[package]]
@@ -1177,6 +1189,15 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memoffset"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
dependencies = [
"autocfg",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
@@ -1224,6 +1245,19 @@ dependencies = [
"unicode-segmentation",
]
[[package]]
name = "nix"
version = "0.26.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
dependencies = [
"bitflags 1.3.2",
"cfg-if",
"libc",
"memoffset",
"pin-utils",
]
[[package]]
name = "nix"
version = "0.28.0"
@@ -1482,6 +1516,12 @@ version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkcs1"
version = "0.7.5"
@@ -1862,6 +1902,7 @@ version = "0.3.1"
dependencies = [
"anyhow",
"fuzzy-matcher",
"homedir",
"inquire",
"lazy_static",
"lexopt",
@@ -2992,6 +3033,12 @@ version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "widestring"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311"
[[package]]
name = "winapi"
version = "0.3.9"
@@ -3023,6 +3070,59 @@ dependencies = [
"windows-targets 0.48.1",
]
[[package]]
name = "windows"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
dependencies = [
"windows-core",
"windows-targets 0.52.6",
]
[[package]]
name = "windows-core"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"
dependencies = [
"windows-implement",
"windows-interface",
"windows-result",
"windows-targets 0.52.6",
]
[[package]]
name = "windows-implement"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]]
name = "windows-interface"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]]
name = "windows-result"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
@@ -3038,7 +3138,7 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets 0.52.0",
"windows-targets 0.52.6",
]
[[package]]
@@ -3058,17 +3158,18 @@ dependencies = [
[[package]]
name = "windows-targets"
version = "0.52.0"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm 0.52.0",
"windows_aarch64_msvc 0.52.0",
"windows_i686_gnu 0.52.0",
"windows_i686_msvc 0.52.0",
"windows_x86_64_gnu 0.52.0",
"windows_x86_64_gnullvm 0.52.0",
"windows_x86_64_msvc 0.52.0",
"windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_msvc 0.52.6",
"windows_i686_gnu 0.52.6",
"windows_i686_gnullvm",
"windows_i686_msvc 0.52.6",
"windows_x86_64_gnu 0.52.6",
"windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_msvc 0.52.6",
]
[[package]]
@@ -3079,9 +3180,9 @@ checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.0"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
@@ -3091,9 +3192,9 @@ checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
@@ -3103,9 +3204,15 @@ checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
@@ -3115,9 +3222,9 @@ checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
@@ -3127,9 +3234,9 @@ checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
@@ -3139,9 +3246,9 @@ checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
@@ -3151,9 +3258,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "xattr"
@@ -3170,7 +3277,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f29504d0a2ca8c1714781c1395a8a660d2557b2cf9c9669433153fc903e9bfc"
dependencies = [
"nix",
"nix 0.28.0",
"thiserror",
]
+1
View File
@@ -26,6 +26,7 @@ anyhow = { version = "1" }
inquire = { version = "0.7.4", default-features = false, features = ["termion", "editor"] }
lexopt = { version = "0.3.0" }
fuzzy-matcher = "0.3.7"
homedir = { version = "0.3.3" }
lazy_static = { version = "1.5.0" }
libc = { version = "^0.2" }
log = { version = "0.4.19" }
+7 -4
View File
@@ -7,8 +7,6 @@ use std::ffi::OsString;
use anyhow::anyhow;
use radicle_tui as tui;
use radicle_cli::terminal;
use radicle_cli::terminal::{Args, Error, Help};
@@ -141,7 +139,6 @@ impl Args for Options {
#[tokio::main]
pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Result<()> {
use radicle::storage::ReadStorage;
use tui::log;
let (_, rid) = radicle::rad::cwd()
.map_err(|_| anyhow!("this command must be run in the context of a project"))?;
@@ -151,7 +148,10 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
let profile = ctx.profile()?;
let repository = profile.storage.repository(rid).unwrap();
log::enable(&profile, "inbox", "select")?;
if let Err(err) = crate::log::enable() {
println!("{}", err);
}
log::info!("Starting patch selection interface in project {}..", rid);
let context = select::Context {
profile,
@@ -166,6 +166,9 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
.map(|o| serde_json::to_string(&o).unwrap_or_default())
.unwrap_or_default();
log::info!("About to print to `stderr`: {}", output);
log::info!("Exiting inbox selection interface..");
eprint!("{output}");
}
}
+7 -5
View File
@@ -15,10 +15,6 @@ use radicle::issue;
use radicle_cli::terminal;
use radicle_cli::terminal::{Args, Error, Help};
use radicle_tui as tui;
use tui::log;
use crate::cob;
use crate::ui::TerminalInfo;
@@ -160,7 +156,10 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
let rid = options.repo.unwrap_or(rid);
let repository = profile.storage.repository(rid).unwrap();
log::enable(&profile, "issue", "select")?;
if let Err(err) = crate::log::enable() {
println!("{}", err);
}
log::info!("Starting issue selection interface in project {}..", rid);
let context = select::Context {
profile,
@@ -175,6 +174,9 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
.map(|o| serde_json::to_string(&o).unwrap_or_default())
.unwrap_or_default();
log::info!("About to print to `stderr`: {}", output);
log::info!("Exiting issue selection interface..");
eprint!("{output}");
}
}
+7 -5
View File
@@ -13,10 +13,6 @@ use radicle::patch::Status;
use radicle_cli::terminal;
use radicle_cli::terminal::args::{Args, Error, Help};
use radicle_tui as tui;
use tui::log;
use crate::cob::patch;
use crate::cob::patch::Filter;
@@ -160,7 +156,10 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
let rid = options.repo.unwrap_or(rid);
let repository = profile.storage.repository(rid).unwrap();
log::enable(&profile, "patch", "select")?;
if let Err(err) = crate::log::enable() {
println!("{}", err);
}
log::info!("Starting patch selection interface in project {}..", rid);
let context = select::Context {
profile,
@@ -174,6 +173,9 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
.map(|o| serde_json::to_string(&o).unwrap_or_default())
.unwrap_or_default();
log::info!("About to print to `stderr`: {}", output);
log::info!("Exiting patch selection interface..");
eprint!("{output}");
}
}
+32
View File
@@ -0,0 +1,32 @@
use std::fs;
use std::time::SystemTime;
use anyhow::bail;
use homedir::my_home;
use log::LevelFilter;
const PATH: &str = ".radicle-tui/logs";
const PREFIX: &str = "rad-tui-";
/// Enables logging to `$HOME/.radicle-tui/logs/`. Creates folder if it does not
/// exist.
pub fn enable() -> Result<(), anyhow::Error> {
match my_home()? {
Some(home) => {
let path = format!("{}/{}", home.to_string_lossy(), PATH);
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
fs::create_dir_all(path.clone())?;
simple_logging::log_to_file(
format!("{}/{}{}.log", path, PREFIX, now.as_millis()),
LevelFilter::Info,
)?;
Ok(())
}
None => bail!("Failed to read home directory"),
}
}
+1
View File
@@ -3,6 +3,7 @@ mod commands;
mod git;
mod settings;
mod ui;
mod log;
use std::ffi::OsString;
use std::io;