commit 8174009a821e5340485f8e0fe5736027147f1c62 from: witcher date: Sat Dec 24 10:34:09 2022 UTC Replace env_logger with simple_logger With simple_logger the logging level can bet set with an argument instead of relying on an environment variable. This enables the command line flag `-v` for specifying the logging level, which is a little more ergonomic than an environment variable. commit - 55c6cbf79df0b49e557cab18d15ebdc952243d7d commit + 8174009a821e5340485f8e0fe5736027147f1c62 blob - 8650843c081a4be766e353f2af6fb881db944478 blob + f9520baa4ab9d59601d7614eaf0560554785d3b3 --- Cargo.lock +++ Cargo.lock @@ -14,15 +14,6 @@ dependencies = [ ] [[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - -[[package]] name = "android_system_properties" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -148,7 +139,7 @@ dependencies = [ "js-sys", "num-integer", "num-traits", - "time", + "time 0.1.44", "wasm-bindgen", "winapi", ] @@ -193,6 +184,17 @@ dependencies = [ ] [[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + +[[package]] name = "core-foundation-sys" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -397,19 +399,6 @@ dependencies = [ ] [[package]] -name = "env_logger" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - -[[package]] name = "event-listener" version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -641,12 +630,6 @@ source = "registry+https://github.com/rust-lang/crates checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] name = "hyper" version = "0.14.20" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -864,7 +847,7 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -913,6 +896,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 = "once_cell" version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1078,23 +1070,6 @@ dependencies = [ ] [[package]] -name = "regex" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" - -[[package]] name = "reqwest" version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1169,12 +1144,12 @@ dependencies = [ "chrono", "clap", "directories", - "env_logger", "lettre", "log", "reqwest", "rss", "serde", + "simple_logger", "sqlx", "tokio", "toml", @@ -1287,6 +1262,19 @@ dependencies = [ ] [[package]] +name = "simple_logger" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e190a521c2044948158666916d9e872cbb9984f755e9bb3b5b75a836205affcd" +dependencies = [ + "atty", + "colored", + "log", + "time 0.3.17", + "windows-sys 0.42.0", +] + +[[package]] name = "slab" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1501,6 +1489,35 @@ dependencies = [ ] [[package]] +name = "time" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" +dependencies = [ + "itoa", + "libc", + "num_threads", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + +[[package]] +name = "time-macros" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" +dependencies = [ + "time-core", +] + +[[package]] name = "tinyvec" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1845,44 +1862,101 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] [[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + +[[package]] name = "winreg" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" blob - 7b31be0469dd419c967126b2c45c6bcd2e9f080b blob + b46da691e29cfe0591d6f8cb20b01ab3679ea54c --- Cargo.toml +++ Cargo.toml @@ -25,7 +25,7 @@ lettre = { version = "0.10.1", default-features = fals serde = { version = "1.0", features = ["derive"] } directories = "4.0.1" log = "0.4.17" -env_logger = "0.9.0" tokio = { version = "1.21.2", default-features = false, features = ["rt-multi-thread", "macros"] } sqlx = { version = "0.6.2", features = ["runtime-tokio-rustls", "migrate", "sqlite", "offline"] } atom_syndication = "0.11.0" +simple_logger = "4.0.0" blob - c7387c964ec3e2b3c4f9e2e82c5e4e0a3ed9e432 blob + 6834e633d3ce472cb4e6a18b2bd75de2e6a9b34c --- docs/rss-email.1.scd +++ docs/rss-email.1.scd @@ -37,6 +37,9 @@ The following options are recognized by *rss-email*: Specifies a custom urls file to be used instead of the default one at *$XDG_CONFIG_HOME/rss-email/urls* +*-v* + Be verbose. Set multiple times to increase verbosity. + *-h*, *--help* Print help information blob - 22e79fd4bdbbb0fcda3f3e028af9eaa84b7be13d blob + 0ae73f956fd559ea9be022672967673a0edf858f --- src/cli.rs +++ src/cli.rs @@ -17,6 +17,9 @@ pub struct Cli { /// Don't send emails #[clap(long, value_parser)] pub dry_run: bool, + /// Be verbose. Pass multiple times to increase verbosity. + #[clap(short, action = clap::ArgAction::Count)] + pub verbose: u8, /// Email "From" header #[clap(long, value_name = "from", value_parser)] pub mail_from: Option, @@ -44,6 +47,15 @@ impl Cli { let args = Cli::parse(); + // setup logging as soon as possible + let verbosity = match args.verbose { + 0 => log::Level::Warn, + 1 => log::Level::Info, + 2 => log::Level::Debug, + _ => log::Level::Trace, + }; + simple_logger::init_with_level(verbosity)?; + if File::open(&args.database_path).is_err() { debug!( "No database file exists, creating a new one: {:?}", blob - 5ef21d457b08c806796978a19ea6229d0b3783eb blob + 6921a225e360fb04b65ee9b0143ffe15773917af --- src/main.rs +++ src/main.rs @@ -27,9 +27,6 @@ use tokio::task::JoinSet; #[tokio::main] async fn main() -> anyhow::Result<()> { - // TODO: change to simple logger with verbosity specified by user on command line - env_logger::init(); - let config = Arc::new(AppConfig::new()?); let urls = BufReader::new( File::open(config.urls_path.as_str())