Share logging setup helper for node spawns

This commit is contained in:
andrussal 2025-12-10 13:42:09 +01:00
parent 4daf3e3e12
commit 119a3cbfcd
3 changed files with 32 additions and 36 deletions

View File

@ -1,4 +1,26 @@
#![allow(dead_code)]
/// Shared spawn helpers (placeholder).
pub struct SpawnManager;
use std::path::Path;
use nomos_tracing::logging::local::FileConfig;
/// Configure tracing logger to write into `NOMOS_LOG_DIR` if set, else into the
/// provided base dir.
pub fn configure_logging<F>(base_dir: &Path, prefix: &str, set_logger: F)
where
F: FnOnce(FileConfig),
{
if let Ok(env_dir) = std::env::var("NOMOS_LOG_DIR") {
let log_dir = std::path::PathBuf::from(env_dir);
let _ = std::fs::create_dir_all(&log_dir);
set_logger(FileConfig {
directory: log_dir,
prefix: Some(prefix.into()),
});
} else {
set_logger(FileConfig {
directory: base_dir.to_owned(),
prefix: Some(prefix.into()),
});
}
}

View File

@ -18,7 +18,6 @@ use nomos_executor::config::Config;
use nomos_http_api_common::paths::{DA_GET_SHARES_COMMITMENTS, MANTLE_METRICS, MEMPOOL_ADD_TX};
use nomos_network::backends::libp2p::Libp2pInfo;
use nomos_node::api::testing::handlers::HistoricSamplingRequest;
use nomos_tracing::logging::local::FileConfig;
use nomos_tracing_service::LoggerLayer;
use reqwest::Url;
pub use testing_framework_config::nodes::executor::create_executor_config;
@ -31,7 +30,7 @@ use crate::{
common::{
binary::{BinaryConfig, BinaryResolver},
config::{injection::inject_ibd_into_cryptarchia, paths::ensure_recovery_paths},
lifecycle::kill::kill_child,
lifecycle::{kill::kill_child, spawn::configure_logging},
},
},
};
@ -78,21 +77,9 @@ impl Executor {
let _ = ensure_recovery_paths(dir.path());
if !*IS_DEBUG_TRACING {
if let Ok(env_dir) = std::env::var("NOMOS_LOG_DIR") {
let log_dir = PathBuf::from(env_dir);
let _ = std::fs::create_dir_all(&log_dir);
config.tracing.logger = LoggerLayer::File(FileConfig {
directory: log_dir,
prefix: Some(LOGS_PREFIX.into()),
});
} else {
// If no explicit log dir is provided, fall back to a tempdir so we can capture
// logs.
config.tracing.logger = LoggerLayer::File(FileConfig {
directory: dir.path().to_owned(),
prefix: Some(LOGS_PREFIX.into()),
});
}
configure_logging(dir.path(), LOGS_PREFIX, |cfg| {
config.tracing.logger = LoggerLayer::File(cfg);
});
}
config.storage.db_path = dir.path().join("db");

View File

@ -15,7 +15,6 @@ use nomos_da_network_service::MembershipResponse;
use nomos_http_api_common::paths::{CRYPTARCHIA_HEADERS, DA_GET_SHARES_COMMITMENTS};
use nomos_network::backends::libp2p::Libp2pInfo;
use nomos_node::{Config, HeaderId, api::testing::handlers::HistoricSamplingRequest};
use nomos_tracing::logging::local::FileConfig;
use nomos_tracing_service::LoggerLayer;
use reqwest::Url;
pub use testing_framework_config::nodes::validator::create_validator_config;
@ -30,7 +29,7 @@ use crate::{
common::{
binary::{BinaryConfig, BinaryResolver},
config::{injection::inject_ibd_into_cryptarchia, paths::ensure_recovery_paths},
lifecycle::kill::kill_child,
lifecycle::{kill::kill_child, spawn::configure_logging},
},
},
};
@ -102,21 +101,9 @@ impl Validator {
let _ = ensure_recovery_paths(dir.path());
if !*IS_DEBUG_TRACING {
if let Ok(env_dir) = std::env::var("NOMOS_LOG_DIR") {
let log_dir = PathBuf::from(env_dir);
let _ = std::fs::create_dir_all(&log_dir);
config.tracing.logger = LoggerLayer::File(FileConfig {
directory: log_dir,
prefix: Some(LOGS_PREFIX.into()),
});
} else {
// If no explicit log dir is provided, fall back to a tempdir so we can capture
// logs.
config.tracing.logger = LoggerLayer::File(FileConfig {
directory: dir.path().to_owned(),
prefix: Some(LOGS_PREFIX.into()),
});
}
configure_logging(dir.path(), LOGS_PREFIX, |cfg| {
config.tracing.logger = LoggerLayer::File(cfg);
});
}
config.storage.db_path = dir.path().join("db");