Skip to content

Commit c6b4c4e

Browse files
authored
Merge pull request #986 from openmina/feat/logging-control
feat(logs): Add flags to control filesystem logging
2 parents 230a6af + e7fac93 commit c6b4c4e

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

cli/src/commands/node/mod.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,22 @@ pub struct Node {
5656
#[arg(long, env, default_value = "8302")]
5757
pub libp2p_port: u16,
5858

59-
/// Verbosity level
59+
/// Verbosity level (options: trace, debug, info, warn, error)
6060
#[arg(long, short, env, default_value = "info")]
6161
pub verbosity: Level,
6262

63+
/// Disable filesystem logging
64+
#[arg(
65+
long,
66+
env = "OPENMINA_DISABLE_FILESYSTEM_LOGGING",
67+
default_value_t = false
68+
)]
69+
pub disable_filesystem_logging: bool,
70+
71+
/// Specify custom path for log files
72+
#[arg(long, env = "OPENMINA_LOG_PATH", default_value = "$OPENMINA_HOME")]
73+
pub log_path: String,
74+
6375
#[arg(long, short = 'P', alias = "peer")]
6476
pub peers: Vec<P2pConnectionOutgoingInitOpts>,
6577

@@ -131,8 +143,20 @@ impl Node {
131143
pub fn run(self) -> anyhow::Result<()> {
132144
let work_dir = shellexpand::full(&self.work_dir).unwrap().into_owned();
133145

134-
let _guard =
135-
tracing::initialize_with_filesystem_output(self.verbosity, work_dir.clone().into());
146+
let _guard = if !self.disable_filesystem_logging {
147+
let log_output_dir = if self.log_path == "$OPENMINA_HOME" {
148+
work_dir.clone()
149+
} else {
150+
self.log_path.clone()
151+
};
152+
Some(tracing::initialize_with_filesystem_output(
153+
self.verbosity,
154+
log_output_dir.into(),
155+
))
156+
} else {
157+
tracing::initialize(self.verbosity);
158+
None
159+
};
136160

137161
rayon::ThreadPoolBuilder::new()
138162
.num_threads(num_cpus::get().max(2) - 1)

0 commit comments

Comments
 (0)