Skip to content

Commit

Permalink
feat: test tracer (#6025)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
loocapro and mattsse authored Jan 13, 2024
1 parent 030a1fd commit a075c31
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 18 deletions.
32 changes: 25 additions & 7 deletions book/cli/reth/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,56 @@ Database:
- extra: Enables logging for extra debug-level messages
Logging:
--log.stdout.format <FORMAT>
The format to use for logs written to stdout.
[default: terminal]
Possible values:
- json
- logfmt
- terminal
--log.stdout.filter <FILTER>
The filter to use for logs written to stdout.
[default: info]
--log.file.directory <PATH>
The path to put log files in
[default: <CACHE_DIR>/logs]
--log.file.max-size <SIZE>
The maximum size (in MB) of one log file
[default: 200]
--log.file.max-files <COUNT>
The maximum amount of log files that will be stored. If set to 0, background file logging is disabled
[default: 5]
--log.file.filter <FILTER>
The filter to use for logs written to the log file
[default: debug]
--log.file.format <FORMAT>
The format to use for logs written to the log file.
[default: Terminal]
Possible values:
- json
- logfmt
- terminal
--log.journald
Write logs to journald
--log.journald.filter <FILTER>
The filter to use for logs written to journald
[default: error]
--color <COLOR>
Sets whether or not the formatter emits ANSI terminal escape codes for colors and other text formatting
[default: always]
Possible values:
Expand All @@ -97,7 +116,6 @@ Logging:
Display:
-v, --verbosity...
Set the minimum log level.
-v Errors
-vv Warnings
-vvv Info
Expand Down
1 change: 0 additions & 1 deletion crates/net/network/src/session/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
use core::sync::atomic::Ordering;
use fnv::FnvHashMap;
use futures::{stream::Fuse, SinkExt, StreamExt};

use reth_eth_wire::{
capability::Capabilities,
errors::{EthHandshakeError, EthStreamError, P2PStreamError},
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,10 +1292,10 @@ mod tests {
use reth_network_api::NetworkInfo;
use reth_primitives::hex;
use reth_provider::test_utils::NoopProvider;

use reth_transaction_pool::test_utils::{testing_pool, MockTransaction};
use secp256k1::SecretKey;
use std::future::poll_fn;

#[tokio::test(flavor = "multi_thread")]
async fn test_ignored_tx_broadcasts_while_initially_syncing() {
reth_tracing::init_test_tracing();
Expand Down
1 change: 0 additions & 1 deletion crates/net/network/tests/it/big_pooled_txs_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use reth_transaction_pool::{
TransactionPool,
};
use tokio::sync::oneshot;

// peer0: `GetPooledTransactions` requestor
// peer1: `GetPooledTransactions` responder
#[tokio::test(flavor = "multi_thread")]
Expand Down
1 change: 0 additions & 1 deletion crates/net/network/tests/it/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use reth_transaction_pool::test_utils::testing_pool;
use secp256k1::SecretKey;
use std::{collections::HashSet, net::SocketAddr, time::Duration};
use tokio::task;

#[tokio::test(flavor = "multi_thread")]
async fn test_establish_connections() {
reth_tracing::init_test_tracing();
Expand Down
1 change: 0 additions & 1 deletion crates/net/network/tests/it/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use reth_primitives::{ChainSpec, Genesis, PeerId, SealedHeader};
use reth_provider::test_utils::NoopProvider;
use secp256k1::SecretKey;
use std::{net::SocketAddr, sync::Arc};

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "geth-tests"), ignore)]
async fn can_peer_with_geth() {
Expand Down
1 change: 0 additions & 1 deletion crates/net/network/tests/it/txgossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use reth_network::test_utils::Testnet;
use reth_primitives::U256;
use reth_provider::test_utils::{ExtendedAccount, MockEthProvider};
use reth_transaction_pool::{test_utils::TransactionGenerator, PoolTransaction, TransactionPool};

#[tokio::test(flavor = "multi_thread")]
async fn test_tx_gossip() {
reth_tracing::init_test_tracing();
Expand Down
10 changes: 5 additions & 5 deletions crates/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use tracing_subscriber::{filter::Directive, EnvFilter};
use tracing_subscriber::filter::Directive;

// Re-export tracing crates
pub use tracing;
Expand All @@ -52,8 +52,11 @@ pub use tracing_subscriber;
pub use formatter::LogFormat;
pub use layers::{FileInfo, FileWorkerGuard};

pub use test_tracer::TestTracer;

mod formatter;
mod layers;
mod test_tracer;

use crate::layers::Layers;
use tracing::level_filters::LevelFilter;
Expand Down Expand Up @@ -223,8 +226,5 @@ impl Tracer for RethTracer {
///
/// The subscriber will silently fail if it could not be installed.
pub fn init_test_tracing() {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_writer(std::io::stderr)
.try_init();
let _ = TestTracer::default().init();
}
25 changes: 25 additions & 0 deletions crates/tracing/src/test_tracer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::EnvFilter;

use crate::Tracer;

/// Initializes a tracing subscriber for tests.
///
/// The filter is configurable via `RUST_LOG`.
///
/// # Note
///
/// The subscriber will silently fail if it could not be installed.
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct TestTracer;

impl Tracer for TestTracer {
fn init(self) -> eyre::Result<Option<WorkerGuard>> {
let _ = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_writer(std::io::stderr)
.try_init();
Ok(None)
}
}

0 comments on commit a075c31

Please sign in to comment.