logs to client_api
This commit is contained in:
parent
7e8eb0c57d
commit
43fd315932
@ -43,6 +43,16 @@ impl veilid_client::Server for VeilidClientImpl {
|
||||
|
||||
Promise::ok(())
|
||||
}
|
||||
|
||||
fn log_message(
|
||||
&mut self,
|
||||
params: veilid_client::LogMessageParams,
|
||||
_results: veilid_client::LogMessageResults,
|
||||
) -> Promise<(), ::capnp::Error> {
|
||||
let message = pry!(pry!(params.get()).get_message());
|
||||
self.comproc.add_log_message(message);
|
||||
Promise::ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct ClientApiConnectionInner {
|
||||
|
@ -277,6 +277,10 @@ debug - send a debugging command to the Veilid server
|
||||
self.inner_mut().ui.set_attachment_state(state);
|
||||
}
|
||||
|
||||
pub fn add_log_message(&mut self, message: &str) {
|
||||
self.inner().ui.add_node_event(message);
|
||||
}
|
||||
|
||||
// called by client_api_connection
|
||||
// calls into ui
|
||||
////////////////////////////////////////////
|
||||
|
@ -166,7 +166,7 @@ impl veilid_server::Server for VeilidServerImpl {
|
||||
params: veilid_server::DebugParams,
|
||||
mut results: veilid_server::DebugResults,
|
||||
) -> Promise<(), ::capnp::Error> {
|
||||
trace!("VeilidServerImpl::attach");
|
||||
trace!("VeilidServerImpl::debug");
|
||||
let veilid_api = self.veilid_api.clone();
|
||||
let what = pry!(pry!(params.get()).get_what()).to_owned();
|
||||
|
||||
@ -298,7 +298,7 @@ impl ClientApi {
|
||||
let regs = &mut registration_map.borrow_mut().registrations;
|
||||
for (&id, mut registration) in regs.iter_mut() {
|
||||
if registration.requests_in_flight > 5 {
|
||||
debug!(
|
||||
println!(
|
||||
"too many requests in flight: {}",
|
||||
registration.requests_in_flight
|
||||
);
|
||||
@ -317,7 +317,7 @@ impl ClientApi {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
debug!("Got error: {:?}. Dropping registation.", e);
|
||||
println!("Got error: {:?}. Dropping registation.", e);
|
||||
registration_map2.borrow_mut().registrations.remove(&id);
|
||||
}
|
||||
}));
|
||||
|
@ -14,7 +14,7 @@ pub struct ClientLogChannel {
|
||||
|
||||
impl ClientLogChannel {
|
||||
pub fn new() -> Self {
|
||||
let (sender, receiver) = bounded(1);
|
||||
let (sender, receiver) = bounded(1024);
|
||||
Self {
|
||||
inner: Arc::new(ClientLogChannelInner { sender, receiver }),
|
||||
}
|
||||
@ -27,11 +27,8 @@ impl ClientLogChannel {
|
||||
|
||||
impl std::io::Write for ClientLogChannel {
|
||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||
if let Err(e) = self
|
||||
.inner
|
||||
.sender
|
||||
.try_send(String::from_utf8_lossy(buf).to_string())
|
||||
{
|
||||
let bufstr = String::from_utf8_lossy(buf).to_string();
|
||||
if let Err(e) = self.inner.sender.try_send(bufstr) {
|
||||
match e {
|
||||
TrySendError::Full(_) => Err(std::io::Error::from(std::io::ErrorKind::WouldBlock)),
|
||||
TrySendError::Closed(_) => {
|
||||
|
@ -30,7 +30,7 @@ logging:
|
||||
append: true
|
||||
level: "info"
|
||||
client:
|
||||
enable: false
|
||||
enabled: true
|
||||
level: "info"
|
||||
testing:
|
||||
subnode_index: 0
|
||||
|
@ -4,16 +4,13 @@ use crate::client_log_channel::*;
|
||||
use crate::settings;
|
||||
use async_std::channel::{bounded, Receiver, Sender};
|
||||
use clap::{App, Arg};
|
||||
use futures::*;
|
||||
use lazy_static::*;
|
||||
use log::*;
|
||||
use parking_lot::Mutex;
|
||||
use simplelog::*;
|
||||
use std::cell::RefCell;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::OpenOptions;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use veilid_core::xx::SingleShotEventual;
|
||||
@ -236,7 +233,7 @@ pub async fn main() -> Result<(), String> {
|
||||
logs.push(WriteLogger::new(
|
||||
settings::convert_loglevel(settingsr.logging.file.level),
|
||||
cb.build(),
|
||||
clog,
|
||||
std::io::LineWriter::with_capacity(65536, clog),
|
||||
))
|
||||
}
|
||||
CombinedLogger::init(logs).map_err(|e| format!("failed to init logs: {}", e))?;
|
||||
@ -272,7 +269,7 @@ pub async fn main() -> Result<(), String> {
|
||||
.map_err(|e| format!("VeilidCore startup failed: {}", e))?;
|
||||
|
||||
// Start client api if one is requested
|
||||
let capi = Rc::new(RefCell::new(if settingsr.client_api.enabled {
|
||||
let mut capi = if settingsr.client_api.enabled {
|
||||
let some_capi = client_api::ClientApi::new(veilid_api.clone());
|
||||
some_capi
|
||||
.clone()
|
||||
@ -280,36 +277,37 @@ pub async fn main() -> Result<(), String> {
|
||||
Some(some_capi)
|
||||
} else {
|
||||
None
|
||||
}));
|
||||
};
|
||||
|
||||
// Drop rwlock on settings
|
||||
let auto_attach = settingsr.auto_attach;
|
||||
drop(settingsr);
|
||||
|
||||
// Handle state changes on main thread for capnproto rpc
|
||||
let capi2 = capi.clone();
|
||||
let capi_jh = async_std::task::spawn_local(async move {
|
||||
let capi_jh = capi.clone().map(|capi| {
|
||||
async_std::task::spawn_local(async move {
|
||||
trace!("state change processing started");
|
||||
while let Ok(change) = receiver.recv().await {
|
||||
if let Some(c) = capi2.borrow().as_ref().cloned() {
|
||||
c.handle_state_change(change);
|
||||
}
|
||||
capi.clone().handle_state_change(change);
|
||||
}
|
||||
trace!("state change processing stopped");
|
||||
})
|
||||
});
|
||||
// Handle log messages on main thread for capnproto rpc
|
||||
let capi2 = capi.clone();
|
||||
let capi_jh2 = client_log_channel.map(|client_log_channel| {
|
||||
let capi_jh2 = capi
|
||||
.clone()
|
||||
.map(|capi| {
|
||||
client_log_channel.map(|client_log_channel| {
|
||||
async_std::task::spawn_local(async move {
|
||||
trace!("client logging started");
|
||||
while let Ok(message) = client_log_channel.recv().await {
|
||||
if let Some(c) = capi2.borrow().as_ref().cloned() {
|
||||
c.handle_client_log(message);
|
||||
}
|
||||
capi.clone().handle_client_log(message);
|
||||
}
|
||||
trace!("client logging stopped")
|
||||
})
|
||||
});
|
||||
})
|
||||
})
|
||||
.flatten();
|
||||
|
||||
// Auto-attach if desired
|
||||
if auto_attach {
|
||||
@ -330,7 +328,7 @@ pub async fn main() -> Result<(), String> {
|
||||
}
|
||||
|
||||
// Stop the client api if we have one
|
||||
if let Some(c) = capi.borrow_mut().as_mut().cloned() {
|
||||
if let Some(c) = capi.as_mut().cloned() {
|
||||
c.stop().await;
|
||||
}
|
||||
|
||||
@ -338,7 +336,9 @@ pub async fn main() -> Result<(), String> {
|
||||
veilid_api.shutdown().await;
|
||||
|
||||
// Wait for client api handlers to exit
|
||||
if let Some(capi_jh) = capi_jh {
|
||||
capi_jh.await;
|
||||
}
|
||||
if let Some(capi_jh2) = capi_jh2 {
|
||||
capi_jh2.await;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user