feat: test tracer (#6025)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Luca Provini
2024-01-13 13:38:08 +01:00
committed by GitHub
parent 030a1fd0f8
commit a075c31542
9 changed files with 56 additions and 18 deletions

32
book/cli/reth/init.md vendored
View File

@ -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:
@ -97,7 +116,6 @@ Logging:
Display:
-v, --verbosity...
Set the minimum log level.
-v Errors
-vv Warnings
-vvv Info

View File

@ -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},

View File

@ -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();

View File

@ -12,7 +12,6 @@ use reth_transaction_pool::{
TransactionPool,
};
use tokio::sync::oneshot;
// peer0: `GetPooledTransactions` requestor
// peer1: `GetPooledTransactions` responder
#[tokio::test(flavor = "multi_thread")]

View File

@ -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();

View File

@ -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() {

View File

@ -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();

View File

@ -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;
@ -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;
@ -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();
}

View File

@ -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)
}
}