Add trace level and keep worker guard
This commit is contained in:
parent
fe700973d7
commit
d7aa319c7b
|
@ -24,3 +24,4 @@ rand_chacha = "0.3"
|
|||
multiaddr = "0.18"
|
||||
sha2 = "0.10"
|
||||
uuid = { version = "1", features = ["fast-rng", "v4"] }
|
||||
tracing-appender = "0.2"
|
||||
|
|
|
@ -3,6 +3,8 @@ use nomos_tracing::{
|
|||
metrics::otlp::{create_otlp_metrics_layer, OtlpMetricsConfig},
|
||||
};
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
use tracing::{level_filters::LevelFilter, Level};
|
||||
use tracing_appender::non_blocking::WorkerGuard;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[derive(Default, Copy, Clone)]
|
||||
|
@ -44,10 +46,14 @@ impl FromStr for LogOutput {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn config_tracing(_fmt: LogFormat, log_to: &LogOutput, with_metrics: bool) {
|
||||
pub fn config_tracing(
|
||||
_fmt: LogFormat,
|
||||
log_to: &LogOutput,
|
||||
with_metrics: bool,
|
||||
) -> Option<WorkerGuard> {
|
||||
let mut layers: Vec<Box<dyn tracing_subscriber::Layer<_> + Send + Sync>> = vec![];
|
||||
|
||||
let (log_layer, _) = match log_to {
|
||||
let (log_layer, guard) = match log_to {
|
||||
LogOutput::StdOut => create_writer_layer(std::io::stdout()),
|
||||
LogOutput::StdErr => create_writer_layer(std::io::stderr()),
|
||||
LogOutput::File(path) => create_file_layer(nomos_tracing::logging::local::FileConfig {
|
||||
|
@ -68,5 +74,11 @@ pub fn config_tracing(_fmt: LogFormat, log_to: &LogOutput, with_metrics: bool) {
|
|||
.unwrap();
|
||||
layers.push(Box::new(metrics_layer));
|
||||
}
|
||||
tracing_subscriber::registry().with(layers).init();
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(LevelFilter::from(Level::DEBUG))
|
||||
.with(layers)
|
||||
.init();
|
||||
|
||||
Some(guard)
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ fn load_json_from_file<T: DeserializeOwned>(path: &Path) -> anyhow::Result<T> {
|
|||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let app: SimulationApp = SimulationApp::parse();
|
||||
log::config_tracing(app.log_format, &app.log_to, app.with_metrics);
|
||||
let maybe_guard = log::config_tracing(app.log_format, &app.log_to, app.with_metrics);
|
||||
|
||||
if let Err(e) = app.run() {
|
||||
tracing::error!("error: {}", e);
|
||||
|
|
|
@ -263,7 +263,7 @@ impl Node for MixNode {
|
|||
self.persistent_sender.send(msg).unwrap();
|
||||
}
|
||||
MixOutgoingMessage::FullyUnwrapped(_) => {
|
||||
println!("fully unwrapped message: Node:{}", self.id);
|
||||
tracing::info!("fully unwrapped message: Node:{}", self.id);
|
||||
self.state.num_messages_broadcasted += 1;
|
||||
//TODO: create a tracing event
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue