Skip to content

Commit a075c31

Browse files
loocapromattsse
andauthored
feat: test tracer (paradigmxyz#6025)
Co-authored-by: Matthias Seitz <[email protected]>
1 parent 030a1fd commit a075c31

File tree

9 files changed

+56
-18
lines changed

9 files changed

+56
-18
lines changed

book/cli/reth/init.md

+25-7
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,56 @@ Database:
5656
- extra: Enables logging for extra debug-level messages
5757
5858
Logging:
59+
--log.stdout.format <FORMAT>
60+
The format to use for logs written to stdout.
61+
62+
[default: terminal]
63+
64+
Possible values:
65+
- json
66+
- logfmt
67+
- terminal
68+
69+
--log.stdout.filter <FILTER>
70+
The filter to use for logs written to stdout.
71+
72+
[default: info]
73+
5974
--log.file.directory <PATH>
6075
The path to put log files in
61-
6276
[default: <CACHE_DIR>/logs]
6377
6478
--log.file.max-size <SIZE>
6579
The maximum size (in MB) of one log file
66-
6780
[default: 200]
6881
6982
--log.file.max-files <COUNT>
7083
The maximum amount of log files that will be stored. If set to 0, background file logging is disabled
71-
7284
[default: 5]
7385
7486
--log.file.filter <FILTER>
7587
The filter to use for logs written to the log file
76-
7788
[default: debug]
7889
90+
--log.file.format <FORMAT>
91+
The format to use for logs written to the log file.
92+
93+
[default: Terminal]
94+
95+
Possible values:
96+
- json
97+
- logfmt
98+
- terminal
99+
79100
--log.journald
80101
Write logs to journald
81102
82103
--log.journald.filter <FILTER>
83104
The filter to use for logs written to journald
84-
85105
[default: error]
86106
87107
--color <COLOR>
88108
Sets whether or not the formatter emits ANSI terminal escape codes for colors and other text formatting
89-
90109
[default: always]
91110
92111
Possible values:
@@ -97,7 +116,6 @@ Logging:
97116
Display:
98117
-v, --verbosity...
99118
Set the minimum log level.
100-
101119
-v Errors
102120
-vv Warnings
103121
-vvv Info

crates/net/network/src/session/active.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::{
1212
use core::sync::atomic::Ordering;
1313
use fnv::FnvHashMap;
1414
use futures::{stream::Fuse, SinkExt, StreamExt};
15-
1615
use reth_eth_wire::{
1716
capability::Capabilities,
1817
errors::{EthHandshakeError, EthStreamError, P2PStreamError},

crates/net/network/src/transactions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1292,10 +1292,10 @@ mod tests {
12921292
use reth_network_api::NetworkInfo;
12931293
use reth_primitives::hex;
12941294
use reth_provider::test_utils::NoopProvider;
1295+
12951296
use reth_transaction_pool::test_utils::{testing_pool, MockTransaction};
12961297
use secp256k1::SecretKey;
12971298
use std::future::poll_fn;
1298-
12991299
#[tokio::test(flavor = "multi_thread")]
13001300
async fn test_ignored_tx_broadcasts_while_initially_syncing() {
13011301
reth_tracing::init_test_tracing();

crates/net/network/tests/it/big_pooled_txs_req.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use reth_transaction_pool::{
1212
TransactionPool,
1313
};
1414
use tokio::sync::oneshot;
15-
1615
// peer0: `GetPooledTransactions` requestor
1716
// peer1: `GetPooledTransactions` responder
1817
#[tokio::test(flavor = "multi_thread")]

crates/net/network/tests/it/connect.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use reth_transaction_pool::test_utils::testing_pool;
2121
use secp256k1::SecretKey;
2222
use std::{collections::HashSet, net::SocketAddr, time::Duration};
2323
use tokio::task;
24-
2524
#[tokio::test(flavor = "multi_thread")]
2625
async fn test_establish_connections() {
2726
reth_tracing::init_test_tracing();

crates/net/network/tests/it/geth.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use reth_primitives::{ChainSpec, Genesis, PeerId, SealedHeader};
1313
use reth_provider::test_utils::NoopProvider;
1414
use secp256k1::SecretKey;
1515
use std::{net::SocketAddr, sync::Arc};
16-
1716
#[tokio::test(flavor = "multi_thread")]
1817
#[cfg_attr(not(feature = "geth-tests"), ignore)]
1918
async fn can_peer_with_geth() {

crates/net/network/tests/it/txgossip.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use reth_network::test_utils::Testnet;
55
use reth_primitives::U256;
66
use reth_provider::test_utils::{ExtendedAccount, MockEthProvider};
77
use reth_transaction_pool::{test_utils::TransactionGenerator, PoolTransaction, TransactionPool};
8-
98
#[tokio::test(flavor = "multi_thread")]
109
async fn test_tx_gossip() {
1110
reth_tracing::init_test_tracing();

crates/tracing/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
)]
4343
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
4444

45-
use tracing_subscriber::{filter::Directive, EnvFilter};
45+
use tracing_subscriber::filter::Directive;
4646

4747
// Re-export tracing crates
4848
pub use tracing;
@@ -52,8 +52,11 @@ pub use tracing_subscriber;
5252
pub use formatter::LogFormat;
5353
pub use layers::{FileInfo, FileWorkerGuard};
5454

55+
pub use test_tracer::TestTracer;
56+
5557
mod formatter;
5658
mod layers;
59+
mod test_tracer;
5760

5861
use crate::layers::Layers;
5962
use tracing::level_filters::LevelFilter;
@@ -223,8 +226,5 @@ impl Tracer for RethTracer {
223226
///
224227
/// The subscriber will silently fail if it could not be installed.
225228
pub fn init_test_tracing() {
226-
let _ = tracing_subscriber::fmt()
227-
.with_env_filter(EnvFilter::from_default_env())
228-
.with_writer(std::io::stderr)
229-
.try_init();
229+
let _ = TestTracer::default().init();
230230
}

crates/tracing/src/test_tracer.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use tracing_appender::non_blocking::WorkerGuard;
2+
use tracing_subscriber::EnvFilter;
3+
4+
use crate::Tracer;
5+
6+
/// Initializes a tracing subscriber for tests.
7+
///
8+
/// The filter is configurable via `RUST_LOG`.
9+
///
10+
/// # Note
11+
///
12+
/// The subscriber will silently fail if it could not be installed.
13+
#[derive(Debug, Clone, Default)]
14+
#[non_exhaustive]
15+
pub struct TestTracer;
16+
17+
impl Tracer for TestTracer {
18+
fn init(self) -> eyre::Result<Option<WorkerGuard>> {
19+
let _ = tracing_subscriber::fmt()
20+
.with_env_filter(EnvFilter::from_default_env())
21+
.with_writer(std::io::stderr)
22+
.try_init();
23+
Ok(None)
24+
}
25+
}

0 commit comments

Comments
 (0)