add tokio console

This commit is contained in:
John Smith
2022-11-03 11:28:29 -04:00
parent f1bf883376
commit 404f579baa
10 changed files with 221 additions and 11 deletions

View File

@@ -130,8 +130,20 @@ fn do_clap_matches(default_config_path: &OsStr) -> Result<clap::ArgMatches, clap
.value_name("BOOTSTRAP_NODE_LIST")
.help("Specify a list of bootstrap node dialinfos to use"),
)
.arg(
Arg::new("panic")
.long("panic")
.help("panic on ctrl-c instead of graceful shutdown"),
)
;
#[cfg(feature = "rt-tokio")]
let matches = matches.arg(
Arg::new("console")
.long("console")
.help("enable tokio console"),
);
#[cfg(debug_assertions)]
let matches = matches.arg(
Arg::new("wait-for-debug")
@@ -288,6 +300,11 @@ pub fn process_command_line() -> EyreResult<(Settings, ArgMatches)> {
};
settingsrw.core.network.bootstrap_nodes = bootstrap_list;
}
if matches.occurrences_of("console") != 0 {
settingsrw.logging.console.enabled = true;
}
drop(settingsrw);
// Set specific config settings

View File

@@ -91,8 +91,23 @@ fn main() -> EyreResult<()> {
}
// --- Normal Startup ---
let panic_on_shutdown = matches.occurrences_of("panic") != 0;
ctrlc::set_handler(move || {
shutdown();
if panic_on_shutdown {
let orig_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |panic_info| {
// invoke the default handler and exit the process
orig_hook(panic_info);
let backtrace = backtrace::Backtrace::new();
eprintln!("Backtrace:\n{:?}", backtrace);
std::process::exit(1);
}));
panic!("panic requested");
} else {
shutdown();
}
})
.expect("Error setting Ctrl-C handler");

View File

@@ -41,6 +41,8 @@ logging:
enabled: false
level: 'trace'
grpc_endpoint: 'localhost:4317'
console:
enabled: false
testing:
subnode_index: 0
core:
@@ -416,6 +418,11 @@ pub struct Terminal {
pub level: LogLevel,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Console {
pub enabled: bool,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct File {
pub enabled: bool,
@@ -456,6 +463,7 @@ pub struct Logging {
pub file: File,
pub api: Api,
pub otlp: Otlp,
pub console: Console,
}
#[derive(Debug, Deserialize, Serialize)]
@@ -922,6 +930,7 @@ impl Settings {
set_config_value!(inner.logging.otlp.enabled, value);
set_config_value!(inner.logging.otlp.level, value);
set_config_value!(inner.logging.otlp.grpc_endpoint, value);
set_config_value!(inner.logging.console.enabled, value);
set_config_value!(inner.testing.subnode_index, value);
set_config_value!(inner.core.protected_store.allow_insecure_fallback, value);
set_config_value!(
@@ -1443,6 +1452,7 @@ mod tests {
s.logging.otlp.grpc_endpoint,
NamedSocketAddrs::from_str("localhost:4317").unwrap()
);
assert_eq!(s.logging.console.enabled, false);
assert_eq!(s.testing.subnode_index, 0);
assert_eq!(

View File

@@ -1,6 +1,8 @@
use crate::settings::*;
use crate::*;
use cfg_if::*;
#[cfg(feature = "rt-tokio")]
use console_subscriber::ConsoleLayer;
use opentelemetry::sdk::*;
use opentelemetry::*;
use opentelemetry_otlp::WithExportConfig;
@@ -36,6 +38,19 @@ impl VeilidLogs {
// XXX:
//layers.push(tracing_error::ErrorLayer::default().boxed());
#[cfg(feature = "rt-tokio")]
if settingsr.logging.console.enabled {
let layer = ConsoleLayer::builder()
.with_default_env()
.spawn()
.with_filter(
filter::Targets::new()
.with_target("tokio", Level::TRACE)
.with_target("runtime", Level::TRACE),
);
layers.push(layer.boxed());
}
// Terminal logger
if settingsr.logging.terminal.enabled {
let filter = veilid_core::VeilidLayerFilter::new(