From f757df5dfd049c6e1b476de53907fb53234ee600 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sun, 12 Jul 2020 11:04:35 +0200 Subject: [PATCH] Introduce the stderr logger to the project --- src/bin/indexer.rs | 10 ++++++++++ src/bin/search.rs | 10 ++++++++++ src/bin/serve.rs | 11 ++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/bin/indexer.rs b/src/bin/indexer.rs index 6f490fae7..e7e3e0fdc 100644 --- a/src/bin/indexer.rs +++ b/src/bin/indexer.rs @@ -55,6 +55,10 @@ struct Opt { #[structopt(long, default_value = "4294967296")] max_memory_usage: usize, + /// Verbose mode (-v, -vv, -vvv, etc.) + #[structopt(short, long, parse(from_occurrences))] + verbose: usize, + /// CSV file to index, if unspecified the CSV is read from standard input. csv_file: Option, } @@ -417,6 +421,12 @@ fn compute_words_attributes_docids(wtxn: &mut heed::RwTxn, index: &Index) -> any fn main() -> anyhow::Result<()> { let opt = Opt::from_args(); + stderrlog::new() + .verbosity(opt.verbose) + .show_level(false) + .timestamp(stderrlog::Timestamp::Off) + .init()?; + if let Some(jobs) = opt.jobs { rayon::ThreadPoolBuilder::new().num_threads(jobs).build_global()?; } diff --git a/src/bin/search.rs b/src/bin/search.rs index 92112826a..f7a939637 100644 --- a/src/bin/search.rs +++ b/src/bin/search.rs @@ -20,6 +20,10 @@ struct Opt { #[structopt(long = "db", parse(from_os_str))] database: PathBuf, + /// Verbose mode (-v, -vv, -vvv, etc.) + #[structopt(short, long, parse(from_occurrences))] + verbose: usize, + /// The query string to search for (doesn't support prefix search yet). query: Option, } @@ -27,6 +31,12 @@ struct Opt { fn main() -> anyhow::Result<()> { let opt = Opt::from_args(); + stderrlog::new() + .verbosity(opt.verbose) + .show_level(false) + .timestamp(stderrlog::Timestamp::Off) + .init()?; + std::fs::create_dir_all(&opt.database)?; let env = EnvOpenOptions::new() .map_size(100 * 1024 * 1024 * 1024) // 100 GB diff --git a/src/bin/serve.rs b/src/bin/serve.rs index 9d4ae77d1..35a19e24a 100644 --- a/src/bin/serve.rs +++ b/src/bin/serve.rs @@ -29,6 +29,10 @@ struct Opt { #[structopt(long = "db-size", default_value = "107374182400")] // 100 GB database_size: usize, + /// Verbose mode (-v, -vv, -vvv, etc.) + #[structopt(short, long, parse(from_occurrences))] + verbose: usize, + /// The ip and port on which the database will listen for HTTP requests. #[structopt(short = "l", long, default_value = "127.0.0.1:9700")] http_listen_addr: String, @@ -46,6 +50,12 @@ struct IndexTemplate { async fn main() -> anyhow::Result<()> { let opt = Opt::from_args(); + stderrlog::new() + .verbosity(opt.verbose) + .show_level(false) + .timestamp(stderrlog::Timestamp::Off) + .init()?; + std::fs::create_dir_all(&opt.database)?; let env = EnvOpenOptions::new() .map_size(opt.database_size) @@ -158,7 +168,6 @@ async fn main() -> anyhow::Result<()> { .or(query_route); let addr = SocketAddr::from_str(&opt.http_listen_addr).unwrap(); - println!("listening on http://{}", addr); warp::serve(routes).run(addr).await; Ok(())