Skip to content

Commit

Permalink
chore: improve logs (#6298)
Browse files Browse the repository at this point in the history
* chore: macro_use tracing

* chore: use Display for EvmError/DatabaseError

* update tests

* fix

* s/target :/target:

* format tracing macros
  • Loading branch information
DaniPopes authored Nov 13, 2023
1 parent b3ea19a commit ef3023f
Show file tree
Hide file tree
Showing 78 changed files with 126 additions and 152 deletions.
1 change: 0 additions & 1 deletion crates/anvil/server/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use axum::{
Json,
};
use futures::{future, FutureExt};
use tracing::{trace, warn};

/// Handles incoming JSON-RPC Request
pub async fn handle<Handler: RpcHandler>(
Expand Down
9 changes: 4 additions & 5 deletions crates/anvil/server/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::{
pin::Pin,
task::{Context, Poll},
};
use tracing::{error, trace, warn};

/// An IPC connection for anvil
///
Expand All @@ -33,22 +32,22 @@ impl<Handler: PubSubRpcHandler> IpcEndpoint<Handler> {
///
/// This establishes the ipc endpoint, converts the incoming connections into handled eth
/// connections, See [`PubSubConnection`] that should be spawned
#[tracing::instrument(target = "ipc", skip_all)]
#[instrument(target = "ipc", skip_all)]
pub fn incoming(self) -> io::Result<impl Stream<Item = impl Future<Output = ()>>> {
let IpcEndpoint { handler, endpoint } = self;
trace!( endpoint=?endpoint.path(), "starting ipc server" );
trace!(endpoint=?endpoint.path(), "starting IPC server" );

if cfg!(unix) {
// ensure the file does not exist
if std::fs::remove_file(endpoint.path()).is_ok() {
warn!( endpoint=?endpoint.path(), "removed existing file");
warn!(endpoint=?endpoint.path(), "removed existing file");
}
}

let connections = match endpoint.incoming() {
Ok(connections) => connections,
Err(err) => {
error!(?err, "Failed to create ipc listener");
error!(%err, "Failed to create IPC listener");
return Err(err)
}
};
Expand Down
6 changes: 4 additions & 2 deletions crates/anvil/server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Bootstrap [axum] RPC servers
#![deny(missing_docs, unsafe_code, unused_crate_dependencies)]
#![warn(missing_docs, unused_crate_dependencies)]

#[macro_use]
extern crate tracing;

use anvil_rpc::{
error::RpcError,
Expand All @@ -17,7 +20,6 @@ use hyper::server::conn::AddrIncoming;
use serde::de::DeserializeOwned;
use std::{fmt, net::SocketAddr};
use tower_http::{cors::CorsLayer, trace::TraceLayer};
use tracing::{error, trace};

mod config;

Expand Down
1 change: 0 additions & 1 deletion crates/anvil/server/src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::{
sync::Arc,
task::{Context, Poll},
};
use tracing::{error, trace};

/// The general purpose trait for handling RPC requests and subscriptions
#[async_trait::async_trait]
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/server/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::{
pin::Pin,
task::{Context, Poll},
};
use tracing::trace;

/// Handles incoming Websocket upgrade
///
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use std::{
time::Duration,
};
use tokio::time::{Instant, Interval};
use tracing::{error, trace};

#[derive(Clone, Debug, Parser)]
pub struct NodeArgs {
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ use foundry_utils::types::ToEthers;
use futures::channel::{mpsc::Receiver, oneshot};
use parking_lot::RwLock;
use std::{collections::HashSet, future::Future, sync::Arc, time::Duration};
use tracing::{trace, warn};

/// The client version: `anvil/v{major}.{minor}.{patch}`
pub const CLIENT_VERSION: &str = concat!("anvil/v", env!("CARGO_PKG_VERSION"));
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/backend/cheats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use ethers::types::{Address, Signature};
use foundry_evm::hashbrown::HashSet;
use parking_lot::RwLock;
use std::sync::Arc;
use tracing::trace;

/// Manages user modifications that may affect the node's behavior
///
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use foundry_evm::{
};
use foundry_utils::types::{ToAlloy, ToEthers};
use std::sync::Arc;
use tracing::{trace, warn};

/// Represents an executed transaction (transacted on the DB)
pub struct ExecutedTransaction {
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/backend/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use parking_lot::{
};
use std::{collections::HashMap, sync::Arc, time::Duration};
use tokio::sync::RwLock as AsyncRwLock;
use tracing::trace;

/// Represents a fork of a remote client
///
Expand Down
9 changes: 4 additions & 5 deletions crates/anvil/src/eth/backend/mem/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{
path::{Path, PathBuf},
};
use tempfile::TempDir;
use tracing::{error, trace};

/// On disk state cache
///
Expand Down Expand Up @@ -40,7 +39,7 @@ impl DiskStateCache {
self.temp_dir = Some(temp_dir);
}
Err(err) => {
error!(target: "backend", ?err, "failed to create disk state cache dir");
error!(target: "backend", %err, "failed to create disk state cache dir");
}
}
}
Expand All @@ -65,7 +64,7 @@ impl DiskStateCache {
trace!(target: "backend", ?hash, "wrote state json file");
}
Err(err) => {
error!(target: "backend", ?err, ?hash, "Failed to load state snapshot");
error!(target: "backend", %err, ?hash, "Failed to load state snapshot");
}
};
});
Expand All @@ -83,7 +82,7 @@ impl DiskStateCache {
Some(state)
}
Err(err) => {
error!(target: "backend", ?err, ?hash, "Failed to load state snapshot");
error!(target: "backend", %err, ?hash, "Failed to load state snapshot");
None
}
}
Expand All @@ -95,7 +94,7 @@ impl DiskStateCache {
pub fn remove(&mut self, hash: H256) {
self.with_cache_file(hash, |file| {
foundry_common::fs::remove_file(file).map_err(|err| {
error!(target: "backend", ?err, ?hash, "Failed to remove state snapshot");
error!(target: "backend", %err, %hash, "Failed to remove state snapshot");
})
});
}
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/backend/mem/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use foundry_evm::{
fork::BlockchainDb,
};
use foundry_utils::types::{ToAlloy, ToEthers};
use tracing::{trace, warn};

// reexport for convenience
pub use foundry_evm::{backend::MemDb, revm::db::DatabaseRef};
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ use std::{
};
use storage::{Blockchain, MinedTransaction};
use tokio::sync::RwLock as AsyncRwLock;
use tracing::{trace, warn};
use trie_db::{Recorder, Trie};

pub mod cache;
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/backend/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::eth::error::BlockchainError;
use chrono::{DateTime, NaiveDateTime, Utc};
use parking_lot::RwLock;
use std::{sync::Arc, time::Duration};
use tracing::trace;

/// Returns the `Utc` datetime for the given seconds since unix epoch
pub fn utc_from_secs(secs: u64) -> DateTime<Utc> {
Expand Down
7 changes: 3 additions & 4 deletions crates/anvil/src/eth/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use foundry_evm::{
},
};
use serde::Serialize;
use tracing::error;

pub(crate) type Result<T> = std::result::Result<T, BlockchainError>;

Expand Down Expand Up @@ -280,7 +279,7 @@ pub fn to_rpc_result<T: Serialize>(val: T) -> ResponseResult {
match serde_json::to_value(val) {
Ok(success) => ResponseResult::Success(success),
Err(err) => {
error!("Failed serialize rpc response: {:?}", err);
error!(%err, "Failed serialize rpc response");
ResponseResult::error(RpcError::internal_error())
}
}
Expand All @@ -292,7 +291,7 @@ impl<T: Serialize> ToRpcResponseResult for Result<T> {
Ok(val) => to_rpc_result(val),
Err(err) => match err {
BlockchainError::Pool(err) => {
error!("txpool error: {:?}", err);
error!(%err, "txpool error");
match err {
PoolError::CyclicTransaction => {
RpcError::transaction_rejected("Cyclic transaction detected")
Expand Down Expand Up @@ -367,7 +366,7 @@ impl<T: Serialize> ToRpcResponseResult for Result<T> {
"Invalid input: `max_priority_fee_per_gas` greater than `max_fee_per_gas`",
),
BlockchainError::ForkProvider(err) => {
error!("fork provider error: {:?}", err);
error!(%err, "fork provider error");
RpcError::internal_error_with(format!("Fork Error: {err:?}"))
}
err @ BlockchainError::EvmError(_) => {
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::{
sync::Arc,
task::{Context, Poll},
};
use tracing::trace;

/// Maximum number of entries in the fee history cache
pub const MAX_FEE_HISTORY_CACHE_SIZE: u64 = 2048u64;
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::{
time::Duration,
};
use tokio::time::Interval;
use tracing::trace;

#[derive(Debug, Clone)]
pub struct Miner {
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use ethers::{
use futures::channel::mpsc::{channel, Receiver, Sender};
use parking_lot::{Mutex, RwLock};
use std::{collections::VecDeque, fmt, sync::Arc};
use tracing::{debug, trace, warn};

pub mod transactions;

Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/eth/pool/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
sync::Arc,
time::Instant,
};
use tracing::{trace, warn};

/// A unique identifying marker for a transaction
pub type TxMarker = Vec<u8>;
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::{
time::{Duration, Instant},
};
use tokio::sync::Mutex;
use tracing::{trace, warn};

/// Type alias for filters identified by their id and their expiration timestamp
type FilterMap = Arc<Mutex<HashMap<String, (EthFilter, Instant)>>>;
Expand Down
3 changes: 3 additions & 0 deletions crates/anvil/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[macro_use]
extern crate tracing;

use crate::{
eth::{
backend::{info::StorageInfo, mem},
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/server/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use anvil_core::eth::{
use anvil_rpc::{error::RpcError, response::ResponseResult};
use anvil_server::{PubSubContext, PubSubRpcHandler, RpcHandler};
use ethers::types::FilteredParams;
use tracing::trace;

/// A `RpcHandler` that expects `EthRequest` rpc calls via http
#[derive(Clone)]
Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use futures::StreamExt;
use handler::{HttpEthRpcHandler, PubSubEthRpcHandler};
use std::net::SocketAddr;
use tokio::{io, task::JoinHandle};
use tracing::trace;

mod handler;

Expand Down
1 change: 0 additions & 1 deletion crates/anvil/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::{
task::{Context, Poll},
};
use tokio::time::Interval;
use tracing::trace;

/// The type that drives the blockchain's state
///
Expand Down
5 changes: 4 additions & 1 deletion crates/binder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#![warn(unused_crate_dependencies)]

#[macro_use]
extern crate tracing;

use crate::utils::{GitReference, GitRemote};
use ethers_contract::MultiAbigen;
pub use foundry_config::Config;
Expand All @@ -10,7 +13,7 @@ use std::{
process::{Command, Stdio},
};
use tempfile::{tempdir, TempDir};
use tracing::trace;

pub use url::Url;

pub mod utils;
Expand Down
1 change: 0 additions & 1 deletion crates/binder/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::{
path::{Path, PathBuf},
process::Command,
};
use tracing::{debug, info};
use url::Url;

/// Represents a remote repository.
Expand Down
3 changes: 1 addition & 2 deletions crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use foundry_evm::{
utils::configure_tx_env,
};
use foundry_utils::types::ToAlloy;
use tracing::trace;

/// CLI arguments for `cast run`.
#[derive(Debug, Clone, Parser)]
Expand Down Expand Up @@ -196,7 +195,7 @@ impl RunArgs {
configure_tx_env(&mut env, &tx);

if let Some(to) = tx.to {
trace!(tx=?tx.hash,to=?to, "executing call transaction");
trace!(tx=?tx.hash, to=?to, "executing call transaction");
TraceResult::from(executor.commit_tx_with_env(env)?)
} else {
trace!(tx=?tx.hash, "executing create transaction");
Expand Down
3 changes: 3 additions & 0 deletions crates/cast/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[macro_use]
extern crate tracing;

use alloy_primitives::{keccak256, Address, B256};
use cast::{Cast, SimpleCast};
use clap::{CommandFactory, Parser};
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl Cheatcodes {
/// Cleanup any previously applied cheatcodes that altered the state in such a way that revm's
/// revert would run into issues.
pub fn on_revert<DB: DatabaseExt>(&mut self, data: &mut EVMData<'_, DB>) {
trace!(deals = ?self.eth_deals.len(), "rolling back deals");
trace!(deals=?self.eth_deals.len(), "rolling back deals");

// Delay revert clean up until expected revert is handled, if set.
if self.expected_revert.is_some() {
Expand Down
3 changes: 1 addition & 2 deletions crates/cheatcodes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ extern crate tracing;
use alloy_primitives::Address;
use foundry_evm_core::backend::DatabaseExt;
use revm::EVMData;
use tracing::Level;

pub use defs::{CheatcodeDef, Vm};

Expand Down Expand Up @@ -67,7 +66,7 @@ pub(crate) trait Cheatcode: CheatcodeDef {

// Separate functions to avoid inline and monomorphization bloat.
fn trace_span<T: Cheatcode>(cheat: &T) -> tracing::Span {
if enabled!(Level::TRACE) {
if enabled!(tracing::Level::TRACE) {
trace_span!(target: "cheatcodes", "apply", cheat=?cheat)
} else {
debug_span!(target: "cheatcodes", "apply", id=%T::CHEATCODE.func.id)
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ macro_rules! p_println {

/// Loads a dotenv file, from the cwd and the project root, ignoring potential failure.
///
/// We could use `tracing::warn!` here, but that would imply that the dotenv file can't configure
/// We could use `warn!` here, but that would imply that the dotenv file can't configure
/// the logging behavior of Foundry.
///
/// Similarly, we could just use `eprintln!`, but colors are off limits otherwise dotenv is implied
Expand Down Expand Up @@ -259,11 +259,11 @@ pub trait CommandUtils {
impl CommandUtils for Command {
#[track_caller]
fn exec(&mut self) -> Result<Output> {
tracing::trace!(command=?self, "executing");
trace!(command=?self, "executing");

let output = self.output()?;

tracing::trace!(code=?output.status.code(), ?output);
trace!(code=?output.status.code(), ?output);

if output.status.success() {
Ok(output)
Expand Down
Loading

0 comments on commit ef3023f

Please sign in to comment.