This commit is contained in:
John Smith 2022-03-10 19:00:59 -05:00
parent b6db4f7b8c
commit 2a9522cc24
3 changed files with 18 additions and 18 deletions

View File

@ -13,11 +13,11 @@ use std::sync::mpsc::TrySendError as StdTrySendError;
//////////////////////////////////////////
#[derive(Clone)]
pub struct ClientLogChannelCloser {
pub struct LogSafeChannelCloser {
sender: Arc<Mutex<Option<StdSender<String>>>>,
}
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<Mutex<Option<StdSender<String>>>>,
}
impl std::io::Write for ClientLogChannelWriterShim {
impl std::io::Write for LogSafeChannelWriterShim {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
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<ClientLogChannelWriterShim>;
pub type LogSafeChannelWriter = std::io::LineWriter<LogSafeChannelWriterShim>;
//////////////////////////////////////////
#[derive(Clone)]
pub struct ClientLogChannel {
pub struct LogSafeChannel {
async_receiver: AsyncReceiver<String>,
}
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,
},
)

View File

@ -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)]

View File

@ -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<ClientLogChannel>,
pub client_log_channel_closer: Option<ClientLogChannelCloser>,
pub client_log_channel: Option<LogSafeChannel>,
pub client_log_channel_closer: Option<LogSafeChannelCloser>,
}
impl VeilidLogs {
@ -15,8 +15,8 @@ impl VeilidLogs {
// Set up loggers
let mut logs: Vec<Box<dyn SharedLogger>> = Vec::new();
let mut client_log_channel: Option<ClientLogChannel> = None;
let mut client_log_channel_closer: Option<ClientLogChannelCloser> = None;
let mut client_log_channel: Option<LogSafeChannel> = None;
let mut client_log_channel_closer: Option<LogSafeChannelCloser> = 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(