log work
This commit is contained in:
parent
b6db4f7b8c
commit
2a9522cc24
@ -13,11 +13,11 @@ use std::sync::mpsc::TrySendError as StdTrySendError;
|
|||||||
|
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ClientLogChannelCloser {
|
pub struct LogSafeChannelCloser {
|
||||||
sender: Arc<Mutex<Option<StdSender<String>>>>,
|
sender: Arc<Mutex<Option<StdSender<String>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientLogChannelCloser {
|
impl LogSafeChannelCloser {
|
||||||
pub fn close(&self) {
|
pub fn close(&self) {
|
||||||
// Drop the sender
|
// Drop the sender
|
||||||
self.sender.lock().take();
|
self.sender.lock().take();
|
||||||
@ -25,11 +25,11 @@ impl ClientLogChannelCloser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
pub struct ClientLogChannelWriterShim {
|
pub struct LogSafeChannelWriterShim {
|
||||||
sender: Arc<Mutex<Option<StdSender<String>>>>,
|
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> {
|
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||||
let bufstr = String::from_utf8_lossy(buf).to_string();
|
let bufstr = String::from_utf8_lossy(buf).to_string();
|
||||||
let sender = self.sender.lock();
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct ClientLogChannel {
|
pub struct LogSafeChannel {
|
||||||
async_receiver: AsyncReceiver<String>,
|
async_receiver: AsyncReceiver<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientLogChannel {
|
impl LogSafeChannel {
|
||||||
pub fn new() -> (Self, ClientLogChannelWriter, ClientLogChannelCloser) {
|
pub fn new() -> (Self, LogSafeChannelWriter, LogSafeChannelCloser) {
|
||||||
let (async_sender, async_receiver) = async_bounded(1024);
|
let (async_sender, async_receiver) = async_bounded(1024);
|
||||||
let (std_sender, std_receiver) = std_sync_channel(1024);
|
let (std_sender, std_receiver) = std_sync_channel(1024);
|
||||||
let shared_std_sender = Arc::new(Mutex::new(Some(std_sender)));
|
let shared_std_sender = Arc::new(Mutex::new(Some(std_sender)));
|
||||||
@ -86,13 +86,13 @@ impl ClientLogChannel {
|
|||||||
|
|
||||||
(
|
(
|
||||||
Self { async_receiver },
|
Self { async_receiver },
|
||||||
ClientLogChannelWriter::with_capacity(
|
LogSafeChannelWriter::with_capacity(
|
||||||
65536,
|
65536,
|
||||||
ClientLogChannelWriterShim {
|
LogSafeChannelWriterShim {
|
||||||
sender: shared_std_sender.clone(),
|
sender: shared_std_sender.clone(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ClientLogChannelCloser {
|
LogSafeChannelCloser {
|
||||||
sender: shared_std_sender,
|
sender: shared_std_sender,
|
||||||
},
|
},
|
||||||
)
|
)
|
@ -3,8 +3,8 @@
|
|||||||
#![deny(unused_must_use)]
|
#![deny(unused_must_use)]
|
||||||
|
|
||||||
mod client_api;
|
mod client_api;
|
||||||
mod client_log_channel;
|
|
||||||
mod cmdline;
|
mod cmdline;
|
||||||
|
mod log_safe_channel;
|
||||||
mod server;
|
mod server;
|
||||||
mod settings;
|
mod settings;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use crate::client_log_channel::*;
|
use crate::log_safe_channel::*;
|
||||||
use crate::settings::*;
|
use crate::settings::*;
|
||||||
use simplelog::*;
|
use simplelog::*;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub struct VeilidLogs {
|
pub struct VeilidLogs {
|
||||||
pub client_log_channel: Option<ClientLogChannel>,
|
pub client_log_channel: Option<LogSafeChannel>,
|
||||||
pub client_log_channel_closer: Option<ClientLogChannelCloser>,
|
pub client_log_channel_closer: Option<LogSafeChannelCloser>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VeilidLogs {
|
impl VeilidLogs {
|
||||||
@ -15,8 +15,8 @@ impl VeilidLogs {
|
|||||||
|
|
||||||
// Set up loggers
|
// Set up loggers
|
||||||
let mut logs: Vec<Box<dyn SharedLogger>> = Vec::new();
|
let mut logs: Vec<Box<dyn SharedLogger>> = Vec::new();
|
||||||
let mut client_log_channel: Option<ClientLogChannel> = None;
|
let mut client_log_channel: Option<LogSafeChannel> = None;
|
||||||
let mut client_log_channel_closer: Option<ClientLogChannelCloser> = None;
|
let mut client_log_channel_closer: Option<LogSafeChannelCloser> = None;
|
||||||
let mut cb = ConfigBuilder::new();
|
let mut cb = ConfigBuilder::new();
|
||||||
for ig in veilid_core::DEFAULT_LOG_IGNORE_LIST {
|
for ig in veilid_core::DEFAULT_LOG_IGNORE_LIST {
|
||||||
cb.add_filter_ignore_str(ig);
|
cb.add_filter_ignore_str(ig);
|
||||||
@ -55,7 +55,7 @@ impl VeilidLogs {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
if settingsr.logging.client.enabled {
|
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 = Some(clog);
|
||||||
client_log_channel_closer = Some(clogcloser);
|
client_log_channel_closer = Some(clogcloser);
|
||||||
logs.push(WriteLogger::new(
|
logs.push(WriteLogger::new(
|
||||||
|
Loading…
Reference in New Issue
Block a user