From 2a9522cc24f831ab07b7852b68061b825f3653d9 Mon Sep 17 00:00:00 2001 From: John Smith Date: Thu, 10 Mar 2022 19:00:59 -0500 Subject: [PATCH] log work --- ...ent_log_channel.rs => log_safe_channel.rs} | 22 +++++++++---------- veilid-server/src/main.rs | 2 +- veilid-server/src/veilid_logs.rs | 12 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) rename veilid-server/src/{client_log_channel.rs => log_safe_channel.rs} (84%) diff --git a/veilid-server/src/client_log_channel.rs b/veilid-server/src/log_safe_channel.rs similarity index 84% rename from veilid-server/src/client_log_channel.rs rename to veilid-server/src/log_safe_channel.rs index e41d57e2..a217bd47 100644 --- a/veilid-server/src/client_log_channel.rs +++ b/veilid-server/src/log_safe_channel.rs @@ -13,11 +13,11 @@ use std::sync::mpsc::TrySendError as StdTrySendError; ////////////////////////////////////////// #[derive(Clone)] -pub struct ClientLogChannelCloser { +pub struct LogSafeChannelCloser { sender: Arc>>>, } -impl ClientLogChannelCloser { +impl LogSafeChannelCloser { pub fn close(&self) { // Drop the sender self.sender.lock().take(); @@ -25,11 +25,11 @@ impl ClientLogChannelCloser { } ////////////////////////////////////////// -pub struct ClientLogChannelWriterShim { +pub struct LogSafeChannelWriterShim { sender: Arc>>>, } -impl std::io::Write for ClientLogChannelWriterShim { +impl std::io::Write for LogSafeChannelWriterShim { fn write(&mut self, buf: &[u8]) -> std::io::Result { let bufstr = String::from_utf8_lossy(buf).to_string(); let sender = self.sender.lock(); @@ -55,17 +55,17 @@ impl std::io::Write for ClientLogChannelWriterShim { } } -pub type ClientLogChannelWriter = std::io::LineWriter; +pub type LogSafeChannelWriter = std::io::LineWriter; ////////////////////////////////////////// #[derive(Clone)] -pub struct ClientLogChannel { +pub struct LogSafeChannel { async_receiver: AsyncReceiver, } -impl ClientLogChannel { - pub fn new() -> (Self, ClientLogChannelWriter, ClientLogChannelCloser) { +impl LogSafeChannel { + pub fn new() -> (Self, LogSafeChannelWriter, LogSafeChannelCloser) { let (async_sender, async_receiver) = async_bounded(1024); let (std_sender, std_receiver) = std_sync_channel(1024); let shared_std_sender = Arc::new(Mutex::new(Some(std_sender))); @@ -86,13 +86,13 @@ impl ClientLogChannel { ( Self { async_receiver }, - ClientLogChannelWriter::with_capacity( + LogSafeChannelWriter::with_capacity( 65536, - ClientLogChannelWriterShim { + LogSafeChannelWriterShim { sender: shared_std_sender.clone(), }, ), - ClientLogChannelCloser { + LogSafeChannelCloser { sender: shared_std_sender, }, ) diff --git a/veilid-server/src/main.rs b/veilid-server/src/main.rs index 81025cd1..de48254f 100644 --- a/veilid-server/src/main.rs +++ b/veilid-server/src/main.rs @@ -3,8 +3,8 @@ #![deny(unused_must_use)] mod client_api; -mod client_log_channel; mod cmdline; +mod log_safe_channel; mod server; mod settings; #[cfg(unix)] diff --git a/veilid-server/src/veilid_logs.rs b/veilid-server/src/veilid_logs.rs index ec7beef5..740b942e 100644 --- a/veilid-server/src/veilid_logs.rs +++ b/veilid-server/src/veilid_logs.rs @@ -1,12 +1,12 @@ -use crate::client_log_channel::*; +use crate::log_safe_channel::*; use crate::settings::*; use simplelog::*; use std::fs::OpenOptions; use std::path::Path; pub struct VeilidLogs { - pub client_log_channel: Option, - pub client_log_channel_closer: Option, + pub client_log_channel: Option, + pub client_log_channel_closer: Option, } impl VeilidLogs { @@ -15,8 +15,8 @@ impl VeilidLogs { // Set up loggers let mut logs: Vec> = Vec::new(); - let mut client_log_channel: Option = None; - let mut client_log_channel_closer: Option = None; + let mut client_log_channel: Option = None; + let mut client_log_channel_closer: Option = None; let mut cb = ConfigBuilder::new(); for ig in veilid_core::DEFAULT_LOG_IGNORE_LIST { cb.add_filter_ignore_str(ig); @@ -55,7 +55,7 @@ impl VeilidLogs { )) } if settingsr.logging.client.enabled { - let (clog, clogwriter, clogcloser) = ClientLogChannel::new(); + let (clog, clogwriter, clogcloser) = LogSafeChannel::new(); client_log_channel = Some(clog); client_log_channel_closer = Some(clogcloser); logs.push(WriteLogger::new(