Skip to content

Commit

Permalink
feat: Update event formatter and observability formatter (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
MexicanAce authored Nov 29, 2023
1 parent 7f68fc4 commit 5307734
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 13 deletions.
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "era_test_node"
version = "0.1.0-alpha.10"
version = "0.1.0-alpha.11"
edition = "2018"
authors = ["The Matter Labs Team <[email protected]>"]
homepage = "https://zksync.io/"
Expand Down Expand Up @@ -38,7 +38,7 @@ clap = { version = "4.2.4", features = ["derive"] }
reqwest = { version = "0.11", features = ["blocking"] }
serde = { version = "1.0", features = ["derive"] }
tracing = { version = "0.1.26", features = ["log"] }
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter", "time", "json"] }
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter", "time", "json", "local-time"] }
colored = "2.0"
lazy_static = "1.4"
eyre = "0.6"
Expand All @@ -50,6 +50,7 @@ itertools = "0.10.5"
rustc-hash = "1.1.0"
indexmap = "2.0.1"
chrono = { version = "0.4.31", default-features = false }
time = "0.3.30"

[dev-dependencies]
httptest = "0.15.4"
Expand Down
42 changes: 39 additions & 3 deletions src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
use crate::{node::ShowCalls, resolver};

use colored::Colorize;

use serde::Deserialize;
use std::collections::HashMap;
use std::str;

use crate::fork::block_on;
use zksync_basic_types::H160;
Expand Down Expand Up @@ -74,12 +76,46 @@ pub fn print_event(event: &VmEvent, resolve_hashes: bool) {
}

tracing::info!(
"{} {}",
"{}",
address_to_human_readable(event.address)
.map(|x| format!("{:42}", x.blue()))
.unwrap_or(format!("{:42}", format!("{:?}", event.address).blue())),
tt.join(", ")
.unwrap_or(format!("{:42}", format!("{:?}", event.address).blue()))
);

tracing::info!("{}", " Topics:".truecolor(128, 128, 128));
for indexed_topic in &tt {
tracing::info!(" {}", indexed_topic);
}

if event.value.is_empty() {
tracing::info!("{}", " Data: EMPTY".truecolor(128, 128, 128));
} else {
match str::from_utf8(&event.value) {
Ok(v) => {
tracing::info!(
"{} {}",
" Data (String):".truecolor(128, 128, 128),
v.to_string()
);
}
Err(_) => {
let hex_str = hex::encode(&event.value);
let display_str = if hex_str.len() > 200 {
format!("{}...", &hex_str[..200])
} else {
hex_str.to_string()
};

tracing::info!(
"{} 0x{}",
" Data (Hex):".truecolor(128, 128, 128),
display_str
);
}
};
}

tracing::info!("");
});
}

Expand Down
1 change: 0 additions & 1 deletion src/node/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,6 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
..Default::default()
};

tracing::info!("");
tracing::info!("");

let bytecodes = vm
Expand Down
30 changes: 24 additions & 6 deletions src/observability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::{fs::File, sync::Mutex};
use clap::ValueEnum;
use serde::{Deserialize, Serialize};
use tracing_subscriber::{
filter::LevelFilter, layer::SubscriberExt, reload, util::SubscriberInitExt, EnvFilter, Layer,
Registry,
filter::LevelFilter, layer::SubscriberExt, reload, util::SubscriberInitExt, EnvFilter, Registry,
};

/// Log filter level for the node.
Expand Down Expand Up @@ -63,14 +62,33 @@ impl Observability {
format!("{log_level_filter}").to_lowercase()
))?;
let (filter, reload_handle) = reload::Layer::new(filter);

let timer_format =
time::format_description::parse("[hour]:[minute]:[second]").expect("Cataplum");
let time_offset = time::UtcOffset::current_local_offset().unwrap_or(time::UtcOffset::UTC);
let timer = tracing_subscriber::fmt::time::OffsetTime::new(time_offset, timer_format);

tracing_subscriber::registry()
.with(filter)
.with(
filter.and_then(tracing_subscriber::fmt::layer()).and_then(
tracing_subscriber::fmt::layer()
.with_writer(Mutex::new(log_file))
.with_ansi(false),
tracing_subscriber::fmt::layer().event_format(
tracing_subscriber::fmt::format()
.compact()
.with_timer(timer.clone())
.with_target(false),
),
)
.with(
tracing_subscriber::fmt::layer()
.event_format(
tracing_subscriber::fmt::format()
.compact()
.with_timer(timer.clone())
.with_target(false),
)
.with_writer(Mutex::new(log_file))
.with_ansi(false),
)
.init();

Ok(Self {
Expand Down

0 comments on commit 5307734

Please sign in to comment.