Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/bin/ant-devnet/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ pub struct Cli {
#[arg(long)]
pub manifest: Option<PathBuf>,

/// Enable logging output.
/// When omitted, the tracing subscriber is not installed and no log
/// records are emitted, even if the binary was built with the
/// `logging` feature. `--log-level` is ignored unless this flag is set.
#[cfg(feature = "logging")]
#[arg(long, env = "ANT_ENABLE_LOGGING")]
pub enable_logging: bool,

/// Log level for devnet process.
#[cfg(feature = "logging")]
#[arg(long, default_value = "info")]
pub log_level: String,

Expand Down
2 changes: 1 addition & 1 deletion src/bin/ant-devnet/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() -> color_eyre::Result<()> {
let cli = Cli::parse();

#[cfg(feature = "logging")]
{
if cli.enable_logging {
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

let filter =
Expand Down
10 changes: 10 additions & 0 deletions src/bin/ant-node/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(name = "ant-node")]
#[command(author, version, about, long_about = None)]
#[allow(clippy::struct_excessive_bools)] // unrelated CLI toggles, not a state machine
pub struct Cli {
/// Root directory for node data.
#[arg(long, env = "ANT_ROOT_DIR")]
Expand Down Expand Up @@ -61,6 +62,15 @@ pub struct Cli {
#[arg(long, default_value = "9100", env = "ANT_METRICS_PORT")]
pub metrics_port: u16,

/// Enable logging output.
/// When omitted, the tracing subscriber is not installed and no log
/// records are emitted, even if the binary was built with the
/// `logging` feature. The remaining `--log-*` options are ignored
/// unless this flag is set.
#[cfg(feature = "logging")]
#[arg(long, env = "ANT_ENABLE_LOGGING")]
pub enable_logging: bool,

/// Log level.
#[cfg(feature = "logging")]
#[arg(long, value_enum, default_value = "info", env = "RUST_LOG")]
Expand Down
20 changes: 14 additions & 6 deletions src/bin/ant-node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ use ant_node::config::BootstrapSource;
use ant_node::NodeBuilder;
use clap::Parser;
use cli::Cli;
#[cfg(feature = "logging")]
use cli::CliLogFormat;
#[cfg(feature = "logging")]
use tracing_subscriber::prelude::*;
#[cfg(feature = "logging")]
use tracing_subscriber::{fmt, EnvFilter, Layer};

/// Initialize the tracing subscriber when the `logging` feature is active.
/// Initialize the tracing subscriber when the `logging` feature is active
/// **and** the user passed `--enable-logging`.
///
/// Returns a guard that must be held for the lifetime of the process to ensure
/// buffered logs are flushed on shutdown.
/// Returns `Ok(None)` when logging was not requested. Otherwise returns a
/// guard (possibly `None` for stdout sinks) that must be held for the
/// lifetime of the process to ensure buffered logs are flushed on shutdown.
#[cfg(feature = "logging")]
fn init_logging(
cli: &Cli,
) -> color_eyre::Result<Option<tracing_appender::non_blocking::WorkerGuard>> {
use cli::CliLogFormat;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter, Layer};
if !cli.enable_logging {
return Ok(None);
}

let log_format = cli.log_format;
let log_dir = cli.log_dir.clone();
Expand Down