From 68b0b70ffddb3d5a8f2f760eba436c1886117bc5 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 22 Feb 2021 01:37:19 -0600 Subject: [PATCH] drop tracing for fern --- Cargo.lock | 198 +++++---------------------------------- Cargo.toml | 5 +- README.md | 2 + imap/Cargo.toml | 2 +- imap/src/client/inner.rs | 13 ++- imap/src/lib.rs | 2 +- imap/src/response/mod.rs | 9 +- src/config.rs | 5 +- src/lib.rs | 2 +- src/main.rs | 53 +++++------ src/ui/mod.rs | 1 - 11 files changed, 70 insertions(+), 222 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9318a1a..f104a08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,15 +9,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" version = "1.0.38" @@ -152,7 +143,7 @@ version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ - "ansi_term 0.11.0", + "ansi_term", "atty", "bitflags", "strsim 0.8.0", @@ -161,6 +152,17 @@ dependencies = [ "vec_map", ] +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + [[package]] name = "core-foundation" version = "0.9.1" @@ -177,27 +179,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" -[[package]] -name = "crossbeam-channel" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" -dependencies = [ - "autocfg", - "cfg-if", - "lazy_static", -] - [[package]] name = "crossterm" version = "0.19.0" @@ -292,6 +273,16 @@ dependencies = [ "ascii_utils", ] +[[package]] +name = "fern" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9a4820f0ccc8a7afd67c39a0f1a0f4b07ca1725164271a64939d7aeb9af065" +dependencies = [ + "colored", + "log", +] + [[package]] name = "fnv" version = "1.0.7" @@ -575,15 +566,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "matchers" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" -dependencies = [ - "regex-automata", -] - [[package]] name = "memchr" version = "2.3.4" @@ -748,10 +730,12 @@ dependencies = [ "cfg-if", "chrono", "crossterm", + "fern", "format-bytes", "futures", "inotify", "lettre", + "log", "panorama-imap", "parking_lot", "pin-project", @@ -763,9 +747,6 @@ dependencies = [ "tokio-stream", "tokio-util", "toml", - "tracing", - "tracing-appender", - "tracing-subscriber", "webpki-roots", "xdg", ] @@ -778,12 +759,12 @@ dependencies = [ "assert_matches", "derive_builder", "futures", + "log", "nom 6.1.2", "owning_ref", "parking_lot", "tokio", "tokio-rustls", - "tracing", "webpki-roots", ] @@ -965,31 +946,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "regex" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" -dependencies = [ - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" -dependencies = [ - "byteorder", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" - [[package]] name = "remove_dir_all" version = "0.5.3" @@ -1137,15 +1093,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sharded-slab" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" -dependencies = [ - "lazy_static", -] - [[package]] name = "signal-hook" version = "0.1.17" @@ -1277,15 +1224,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "thread_local" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" -dependencies = [ - "once_cell", -] - [[package]] name = "time" version = "0.1.44" @@ -1376,92 +1314,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tracing" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f77d3842f76ca899ff2dbcf231c5c65813dea431301d6eb686279c15c4464f12" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-appender" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9965507e507f12c8901432a33e31131222abac31edd90cabbcf85cf544b7127a" -dependencies = [ - "chrono", - "crossbeam-channel", - "tracing-subscriber", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a9bd1db7706f2373a190b0d067146caa39350c486f3d455b0e33b431f94c07" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "tracing-log" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3" -dependencies = [ - "lazy_static", - "log", - "tracing-core", -] - -[[package]] -name = "tracing-serde" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" -dependencies = [ - "serde", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ab8966ac3ca27126141f7999361cc97dd6fb4b71da04c02044fa9045d98bb96" -dependencies = [ - "ansi_term 0.12.1", - "chrono", - "lazy_static", - "matchers", - "regex", - "serde", - "serde_json", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", - "tracing-serde", -] - [[package]] name = "unicode-segmentation" version = "1.7.1" diff --git a/Cargo.toml b/Cargo.toml index 49216b7..0b44121 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,10 +17,12 @@ async-trait = "0.1.42" cfg-if = "1.0.0" chrono = "0.4.19" crossterm = "0.19.0" +fern = { version = "0.6.0", features = ["colored"] } format-bytes = "0.2.0" futures = "0.3.12" inotify = { version = "0.9.2", features = ["stream"] } lettre = "0.9.5" +log = "0.4.14" panorama-imap = { path = "imap", version = "0" } parking_lot = "0.11.1" pin-project = "1.0.4" @@ -32,9 +34,6 @@ tokio-rustls = "0.22.0" tokio-stream = { version = "0.1.3", features = ["sync"] } tokio-util = { version = "0.6.3", features = ["full"] } toml = "0.5.8" -tracing = "0.1.23" -tracing-appender = "0.1.2" -tracing-subscriber = "0.2.15" webpki-roots = "0.21.0" xdg = "2.2.0" diff --git a/README.md b/README.md index f85f709..5684d47 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ panorama Panorama is a terminal Personal Information Manager (PIM). +Status: **not done yet** + Goals: - Never have to actually close the application. diff --git a/imap/Cargo.toml b/imap/Cargo.toml index da6bae4..401de54 100644 --- a/imap/Cargo.toml +++ b/imap/Cargo.toml @@ -15,12 +15,12 @@ maintenance = { status = "passively-maintained" } anyhow = "1.0.38" derive_builder = "0.9.0" futures = "0.3.12" +log = "0.4.14" nom = { version = "6.1.2", default-features = false, features = ["std"] } owning_ref = "0.4.1" parking_lot = "0.11.1" tokio = { version = "1.1.1", features = ["full"] } tokio-rustls = "0.22.0" -tracing = "0.1.23" webpki-roots = "0.21.0" [dev-dependencies] diff --git a/imap/src/client/inner.rs b/imap/src/client/inner.rs index 430e233..95aef0d 100644 --- a/imap/src/client/inner.rs +++ b/imap/src/client/inner.rs @@ -211,9 +211,16 @@ where pin_mut!(fut2); match future::select(fut, fut2).await { - Either::Left((_, _)) => { - debug!("got a new line"); - let (_, resp) = crate::parser::parse_response(next_line.as_bytes()).unwrap(); + Either::Left((res, _)) => { + res.context("read failed")?; + debug!("got a new line {:?}", next_line); + let (_, resp) = match crate::parser::parse_response(next_line.as_bytes()) { + Ok(v) => v, + Err(err) => { + debug!("shiet: {:?}", err); + continue; + } + }; let resp = Response::from(resp); debug!("parsed as: {:?}", resp); let next_line = next_line.trim_end_matches('\n').trim_end_matches('\r'); diff --git a/imap/src/lib.rs b/imap/src/lib.rs index cd844cf..f613dd8 100644 --- a/imap/src/lib.rs +++ b/imap/src/lib.rs @@ -5,7 +5,7 @@ extern crate derive_builder; #[macro_use] extern crate futures; #[macro_use] -extern crate tracing; +extern crate log; pub mod builders; pub mod client; diff --git a/imap/src/response/mod.rs b/imap/src/response/mod.rs index b609bc8..74589a3 100644 --- a/imap/src/response/mod.rs +++ b/imap/src/response/mod.rs @@ -64,7 +64,7 @@ impl<'a> From> for Response { information: information.map(str::to_owned), }, Expunge(n) => Response::Expunge(n), - Vanished {earlier, uids} => Response::Vanished{earlier, uids}, + Vanished { earlier, uids } => Response::Vanished { earlier, uids }, _ => todo!("nyi: {:?}", b), } } @@ -132,10 +132,7 @@ pub enum UidSetMember { } #[derive(Clone, Debug)] -pub enum AttributeValue { -} +pub enum AttributeValue {} #[derive(Clone, Debug)] -pub enum MailboxDatum { - -} +pub enum MailboxDatum {} diff --git a/src/config.rs b/src/config.rs index 2395966..2900059 100644 --- a/src/config.rs +++ b/src/config.rs @@ -60,10 +60,7 @@ pub enum ImapAuth { /// Use plain username/password authentication #[serde(rename = "plain")] #[allow(missing_docs)] - Plain { - username: String, - password: String, - } + Plain { username: String, password: String }, } /// Describes when to perform the TLS handshake diff --git a/src/lib.rs b/src/lib.rs index 33492e3..f577e6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ extern crate format_bytes; #[macro_use] extern crate serde; #[macro_use] -extern crate tracing; +extern crate log; pub mod config; pub mod mail; diff --git a/src/main.rs b/src/main.rs index a03a18a..dbe48b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,11 @@ #[macro_use] -extern crate tracing; +extern crate log; +use std::fs::OpenOptions; use std::path::PathBuf; use anyhow::Result; +use fern::colors::{Color, ColoredLevelConfig}; use futures::future::TryFutureExt; use panorama::{config::spawn_config_watcher_system, mail, report_err, ui}; use structopt::StructOpt; @@ -20,36 +22,29 @@ struct Opt { #[tokio::main(flavor = "multi_thread")] async fn main() -> Result<()> { - // use panorama::config::*; - // let c = ImapConfig{ - // server:String::from("ouais"), - // port: 1, - // tls: TlsMethod::Starttls, - // auth: ImapAuth::Plain{username:String::from("osu"), password:String::from("game")}, - // }; - // let s = toml::to_string(&c)?; - // println!("{}", s); - // panic!(); - // parse command line arguments into options struct - let _opt = Opt::from_args(); + let opt = Opt::from_args(); - // print logs to file as directed by command line options - use tracing_subscriber::filter::LevelFilter; - - let file = tracing_appender::rolling::daily("public", "lol"); - let (non_blocking, _guard) = tracing_appender::non_blocking(file); - - tracing_subscriber::fmt() - .with_max_level(LevelFilter::TRACE) - .with_writer(non_blocking) - .with_thread_ids(true) - .init(); - debug!("shiet"); - - // TODO: debug - let x = span!(tracing::Level::WARN, "ouais"); - let _y = x.enter(); + let colors = ColoredLevelConfig::new() + .info(Color::Blue) + .debug(Color::BrightBlack) + .warn(Color::Yellow) + .error(Color::Red); + let mut logger = fern::Dispatch::new() + .format(move |out, message, record| { + out.finish(format_args!( + "{}[{}][{}] {}", + chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"), + record.target(), + colors.color(record.level()), + message + )) + }) + .level(log::LevelFilter::Debug); + if let Some(log_file) = opt.log_file { + logger = logger.chain(fern::log_file(log_file)?); + } + logger.apply()?; let _xdg = BaseDirectories::new()?; let (_config_thread, config_update) = spawn_config_watcher_system()?; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 296fc51..a2bb49e 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -27,7 +27,6 @@ const FRAME: Duration = Duration::from_millis(20); pub struct Rect(u16, u16, u16, u16); /// UI entrypoint. -#[instrument(skip(w, exit))] pub async fn run_ui(mut w: impl Write + Debug, exit: ExitSender) -> Result<()> { execute!(w, cursor::Hide, terminal::EnterAlternateScreen)?; terminal::enable_raw_mode()?;