From aa12104e4c5572a5806bf1e6b8dd27d72705ab84 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 1 Feb 2020 09:13:12 -0500 Subject: Improve logging legibility --- src/importer.rs | 9 ++++----- src/main.rs | 20 +++++++++++++++----- src/server.rs | 4 +++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/importer.rs b/src/importer.rs index 8513b54..2966449 100644 --- a/src/importer.rs +++ b/src/importer.rs @@ -14,13 +14,11 @@ pub enum Command { Quit, } -fn handle_command(pool: ThreadPool, - command: Command) { +fn handle_command(pool: ThreadPool, command: Command) { info!("handle {:?}", command); } -fn receive_commands(pool: ThreadPool, - rx: Arc>>) { +fn receive_commands(pool: ThreadPool, rx: Arc>>) { info!("receive_commands"); match (move || -> Result<(), Box> { let rx = rx.lock().expect("channel"); @@ -30,7 +28,8 @@ fn receive_commands(pool: ThreadPool, let pool0 = pool.clone(); pool.execute(|| handle_command(pool0, command)); command = rx.recv()?; - }})() { + } + })() { Ok(()) => (), Err(e) => { error!("receive_commands: {:?}", e); diff --git a/src/main.rs b/src/main.rs index 7ced591..235c71f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,15 +20,25 @@ fn setup_logger() -> Result<(), fern::InitError> { let thread_id = &format!("{:?}", thread.id())[..]; let prefix = "ThreadId("; let thread_id = if thread_id.find(prefix).is_some() { - &thread_id[prefix.len() .. thread_id.len() - 1] + &thread_id[prefix.len()..thread_id.len() - 1] } else { thread_id }; - let thread_colors = [Color::Red, Color::Green, Color::Magenta, - Color::Cyan, Color::White, Color::BrightRed, - Color::BrightGreen, Color::BrightMagenta, - Color::BrightWhite]; + let thread_colors = [ + Color::Red, + Color::Green, + Color::Magenta, + Color::Cyan, + Color::White, + Color::Yellow, + Color::BrightRed, + Color::BrightGreen, + Color::BrightMagenta, + Color::BrightCyan, + Color::BrightBlue, + Color::BrightWhite, + ]; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; let mut hasher = DefaultHasher::new(); diff --git a/src/server.rs b/src/server.rs index c5a59f5..ad163e1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -169,7 +169,9 @@ pub fn start(conn: diesel::PgConnection, db_url: &str, base_url: &str) { let importer_pool = ThreadPool::with_name("import".to_string(), importer::WORKERS); let tx = importer::run(importer_pool.clone()); - tx.send(importer::Command::Quit).expect("send"); + for i in 0..100 { + tx.send(importer::Command::Quit).expect("send"); + } rocket::custom(config) .manage(params) -- cgit v1.2.3