Simlib tracing level (#33)

* Ignore cargo.lock

* Add trace level and keep worker guard
This commit is contained in:
gusto 2024-11-08 04:57:00 +02:00 committed by GitHub
parent 6bc6193e7a
commit 786942ad70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 20 additions and 3564 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ __pycache__/
simulation
simlib/**/target
.idea/
simlib/**/Cargo.lock
simlib/test.json

3559
simlib/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -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"

View File

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

View File

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

View File

@ -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
}