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
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,22 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build release
run: cargo build --release
- name: Build release (no logging)
run: cargo build --release --no-default-features

test-no-logging:
name: Test (no logging)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Run unit tests without logging
run: cargo test --lib --no-default-features

security:
name: Security Audit
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ jobs:
if: matrix.cross
run: cargo install cross --git https://github.com/cross-rs/cross

- name: Build (cross)
- name: Build (cross, no logging)
if: matrix.cross
run: cross build --release --target ${{ matrix.target }}
run: cross build --release --no-default-features --target ${{ matrix.target }}

- name: Build (native)
- name: Build (native, no logging)
if: ${{ !matrix.cross }}
run: cargo build --release --target ${{ matrix.target }}
run: cargo build --release --no-default-features --target ${{ matrix.target }}

- name: Create archive (Unix)
if: matrix.archive == 'tar.gz'
Expand Down
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ directories = "5"
reqwest = { version = "0.13", features = ["json", "rustls"], default-features = false }
semver = "1"

# Logging
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
tracing-appender = "0.2"
# Logging (optional — behind `logging` feature flag)
tracing = { version = "0.1", optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"], optional = true }
tracing-appender = { version = "0.2", optional = true }

# Error handling
thiserror = "2"
Expand Down Expand Up @@ -119,7 +119,12 @@ path = "tests/e2e/mod.rs"
required-features = ["test-utils"]

[features]
default = []
default = ["logging"]
# Enable tracing/logging infrastructure.
# Included in `default` so dev builds (`cargo build`, `cargo test`) get logging
# automatically. Release builds strip it:
# cargo build --release --no-default-features
logging = ["tracing", "tracing-subscriber", "tracing-appender"]
# Enable additional diagnostics for development
dev = []
# Expose test helpers (cache_insert, payment_verifier accessor) for
Expand Down
4 changes: 2 additions & 2 deletions scripts/testnet/build-and-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ ssh -o StrictHostKeyChecking=no "root@${BUILD_HOST}" "
cd /root/ant-node
fi

# Build release binary
cargo build --release
# Build release binary (no logging)
cargo build --release --no-default-features

# Verify binary
ls -la target/release/ant-node
Expand Down
6 changes: 3 additions & 3 deletions scripts/testnet/testnet-endurance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ echo "Log file: ${LOG_FILE}" | tee -a "$LOG_FILE"
echo "Start time: $(date)" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"

# Build the test binary if needed
echo "Building test binary..." | tee -a "$LOG_FILE"
cargo build --release 2>&1 | tee -a "$LOG_FILE"
# Build the binary (no logging)
echo "Building binary..." | tee -a "$LOG_FILE"
cargo build --release --no-default-features 2>&1 | tee -a "$LOG_FILE"

# Export test configuration
export ANT_TEST_BOOTSTRAP="$BOOTSTRAP"
Expand Down
33 changes: 19 additions & 14 deletions src/bin/ant-devnet/main.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
//! ant-devnet CLI entry point.

#![cfg_attr(not(feature = "logging"), allow(unused_variables))]

mod cli;

use ant_node::devnet::{Devnet, DevnetConfig, DevnetEvmInfo, DevnetManifest};
use clap::Parser;
use cli::Cli;
use tracing::info;
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

#[tokio::main]
async fn main() -> color_eyre::Result<()> {
color_eyre::install()?;

let cli = Cli::parse();

let filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&cli.log_level));
#[cfg(feature = "logging")]
{
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

let filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&cli.log_level));

tracing_subscriber::registry()
.with(fmt::layer())
.with(filter)
.init();
tracing_subscriber::registry()
.with(fmt::layer())
.with(filter)
.init();
}

info!("ant-devnet v{}", env!("CARGO_PKG_VERSION"));
ant_node::logging::info!("ant-devnet v{}", env!("CARGO_PKG_VERSION"));

let mut config =
cli.preset
Expand Down Expand Up @@ -55,7 +60,7 @@ async fn main() -> color_eyre::Result<()> {

// Start Anvil and deploy contracts if EVM is enabled
let evm_info = if cli.enable_evm {
info!("Starting local Anvil blockchain for EVM payment enforcement...");
ant_node::logging::info!("Starting local Anvil blockchain for EVM payment enforcement...");
let testnet = evmlib::testnet::Testnet::new()
.await
.map_err(|e| color_eyre::eyre::eyre!("Failed to start Anvil testnet: {e}"))?;
Expand All @@ -79,8 +84,8 @@ async fn main() -> color_eyre::Result<()> {

config.evm_network = Some(network);

info!("Anvil blockchain running at {rpc_url}");
info!("Funded wallet private key: {wallet_key}");
ant_node::logging::info!("Anvil blockchain running at {rpc_url}");
ant_node::logging::info!("Funded wallet private key: {wallet_key}");

// Keep testnet alive by leaking it (it will be cleaned up on process exit)
// This is necessary because AnvilInstance stops Anvil when dropped
Expand Down Expand Up @@ -111,12 +116,12 @@ async fn main() -> color_eyre::Result<()> {
let json = serde_json::to_string_pretty(&manifest)?;
if let Some(path) = cli.manifest {
tokio::fs::write(&path, &json).await?;
info!("Wrote manifest to {}", path.display());
ant_node::logging::info!("Wrote manifest to {}", path.display());
} else {
println!("{json}");
}

info!("Devnet running. Press Ctrl+C to stop.");
ant_node::logging::info!("Devnet running. Press Ctrl+C to stop.");
tokio::signal::ctrl_c().await?;

devnet.shutdown().await?;
Expand Down
12 changes: 11 additions & 1 deletion src/bin/ant-node/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,25 @@ pub struct Cli {
pub metrics_port: u16,

/// Log level.
#[cfg(feature = "logging")]
#[arg(long, value_enum, default_value = "info", env = "RUST_LOG")]
pub log_level: CliLogLevel,

/// Log output format.
#[cfg(feature = "logging")]
#[arg(long, value_enum, default_value = "text", env = "ANT_LOG_FORMAT")]
pub log_format: CliLogFormat,

/// Directory for log file output.
/// When set, logs are written to files in this directory instead of stdout.
/// Files rotate daily and are named ant-node.YYYY-MM-DD.log.
#[cfg(feature = "logging")]
#[arg(long, env = "ANT_LOG_DIR")]
pub log_dir: Option<PathBuf>,

/// Maximum number of rotated log files to retain (only used with --log-dir).
/// Oldest files are deleted when this limit is reached. Rotation is daily.
#[cfg(feature = "logging")]
#[arg(long, default_value = "7", env = "ANT_LOG_MAX_FILES")]
pub log_max_files: usize,

Expand Down Expand Up @@ -136,6 +140,7 @@ pub enum CliEvmNetwork {
}

/// Log level CLI enum.
#[cfg(feature = "logging")]
#[derive(Debug, Clone, Copy, ValueEnum, Default)]
pub enum CliLogLevel {
/// Error messages only.
Expand All @@ -152,6 +157,7 @@ pub enum CliLogLevel {
}

/// Log format CLI enum.
#[cfg(feature = "logging")]
#[derive(Debug, Clone, Copy, ValueEnum, Default)]
pub enum CliLogFormat {
/// Plain text output (default).
Expand Down Expand Up @@ -207,7 +213,10 @@ impl Cli {

config.port = self.port;
config.ipv4_only = self.ipv4_only;
config.log_level = self.log_level.into();
#[cfg(feature = "logging")]
{
config.log_level = self.log_level.into();
}
config.network_mode = self.network_mode.into();

// Apply CLI bootstrap peers if provided; otherwise keep config file value.
Expand Down Expand Up @@ -275,6 +284,7 @@ impl From<CliEvmNetwork> for EvmNetworkConfig {
}
}

#[cfg(feature = "logging")]
impl From<CliLogLevel> for String {
fn from(level: CliLogLevel) -> Self {
match level {
Expand Down
Loading
Loading