Skip to content

Commit

Permalink
feat: add flags to control console logs (#443)
Browse files Browse the repository at this point in the history
* feat: add silent and show-only-contract-logs flags

* fix: lint

* feat: add flags to control logs

* fix: lint

* fix: rename show_calls_summary

* fix: add missing test endpoints
  • Loading branch information
Romsters authored Nov 29, 2024
1 parent 6e6dba2 commit 6863404
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 92 deletions.
88 changes: 88 additions & 0 deletions SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ The `status` options are:
| [`CONFIG`](#config-namespace) | [`config_setShowStorageLogs`](#config_setshowstoragelogs) | `SUPPORTED` | Updates `show_storage_logs` to print storage log reads/writes |
| [`CONFIG`](#config-namespace) | [`config_setShowVmDetails`](#config_setshowvmdetails) | `SUPPORTED` | Updates `show_vm_details` to print more detailed results from vm execution |
| [`CONFIG`](#config-namespace) | [`config_setShowGasDetails`](#config_setshowgasdetails) | `SUPPORTED` | Updates `show_gas_details` to print more details about gas estimation and usage |
| [`CONFIG`](#config-namespace) | [`config_setShowNodeConfig`](#config_setshownodeconfig) | `SUPPORTED` | Updates `show_node_config` to print node config on startup |
| [`CONFIG`](#config-namespace) | [`config_setShowTxSummary`](#config_setshowtxsummary) | `SUPPORTED` | Updates `show_tx_summary` to print transactions and calls summary |
| [`CONFIG`](#config-namespace) | [`config_setDisableConsoleLog`](#config_setdisableconsolelog) | `SUPPORTED` | Updates `disable_console_log` to disable printing of `console.log` invocations to stdout |
| [`CONFIG`](#config-namespace) | [`config_setShowEventLogs`](#config_setshoweventlogs) | `SUPPORTED` | Updates `show_event_logs` to log events |
| [`CONFIG`](#config-namespace) | [`config_setLogLevel`](#config_setloglevel) | `SUPPORTED` | Sets the logging level for the node and only displays the node logs. |
| [`CONFIG`](#config-namespace) | [`config_setLogging`](#config_setlogging) | `SUPPORTED` | Sets the fine-tuned logging levels for the node and any of its dependencies |
| [`DEBUG`](#debug-namespace) | [`debug_traceCall`](#debug_tracecall) | `SUPPORTED` | Performs a call and returns structured traces of the execution |
Expand Down Expand Up @@ -368,6 +372,90 @@ curl --request POST \
--data '{"jsonrpc": "2.0","id": "1","method": "config_setResolveHashes","params": [true]}'
```

### `config_setShowNodeConfig`

[source](src/node/config_api.rs)

Updates `show_node_config` to print node config on startup
#### Arguments

+ `value: boolean`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "config_setShowNodeConfig","params": [true]}'
```

### `config_setShowTxSummary`

[source](src/node/config_api.rs)

Updates `show_tx_summary` to print transactions and calls summary
#### Arguments

+ `value: boolean`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "config_setShowTxSummary","params": [true]}'
```

### `config_setDisableConsoleLog`

[source](src/node/config_api.rs)

Updates `disable_console_log` to disable printing of `console.log` invocations to stdout
#### Arguments

+ `value: boolean`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "config_setDisableConsoleLog","params": [true]}'
```

Updates `show_event_logs` to log events to stdout
#### Arguments

+ `value: boolean`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "config_setShowEventLogs","params": [true]}'
```

### `config_setLogLevel`

[source](src/node/config_api.rs)
Expand Down
29 changes: 27 additions & 2 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,28 @@ pub struct Cli {
/// Enable default settings for debugging contracts.
pub debug_mode: bool,

#[arg(long, default_value = "true", default_missing_value = "true", num_args(0..=1), help_heading = "Debugging Options")]
/// If true, prints node config on startup.
pub show_node_config: Option<bool>,

#[arg(long, default_value = "true", default_missing_value = "true", num_args(0..=1), help_heading = "Debugging Options")]
/// If true, prints transactions and calls summary.
pub show_tx_summary: Option<bool>,

#[arg(long, alias = "no-console-log", default_missing_value = "true", num_args(0..=1), help_heading = "Debugging Options")]
/// Disables printing of `console.log` invocations to stdout if true.
pub disable_console_log: Option<bool>,

#[arg(long, default_missing_value = "true", num_args(0..=1), help_heading = "Debugging Options")]
/// If true, logs events.
pub show_event_logs: Option<bool>,

// Debugging Options
#[arg(long, help_heading = "Debugging Options")]
/// Show call debug information.
pub show_calls: Option<ShowCalls>,

#[arg(long, help_heading = "Debugging Options")]
#[arg(long, default_missing_value = "true", num_args(0..=1), help_heading = "Debugging Options")]
/// Show call output information.
pub show_outputs: Option<bool>,

Expand All @@ -87,7 +103,7 @@ pub struct Cli {
/// Show gas details information.
pub show_gas_details: Option<ShowGasDetails>,

#[arg(long, help_heading = "Debugging Options")]
#[arg(long, default_missing_value = "true", num_args(0..=1), help_heading = "Debugging Options")]
/// If true, the tool will try to resolve ABI and topic names for better readability.
/// May decrease performance.
pub resolve_hashes: Option<bool>,
Expand Down Expand Up @@ -139,6 +155,10 @@ pub struct Cli {
/// Log file path (default: era_test_node.log).
pub log_file_path: Option<String>,

#[arg(long, alias = "quiet", default_missing_value = "true", num_args(0..=1), help_heading = "Logging Configuration")]
/// If true, the tool will not print anything on startup.
pub silent: Option<bool>,

// Cache Options
#[arg(long, help_heading = "Cache Options")]
/// Cache type (none, memory, or disk). Default: "disk".
Expand Down Expand Up @@ -325,11 +345,16 @@ impl Cli {
.with_l1_gas_price(self.l1_gas_price)
.with_l2_gas_price(self.l2_gas_price)
.with_l1_pubdata_price(self.l1_pubdata_price)
.with_show_tx_summary(self.show_tx_summary)
.with_show_event_logs(self.show_event_logs)
.with_disable_console_log(self.disable_console_log)
.with_show_calls(self.show_calls)
.with_vm_log_detail(vm_log_detail)
.with_gas_limit_scale(self.limit_scale_factor)
.with_price_scale(self.price_scale_factor)
.with_resolve_hashes(self.resolve_hashes)
.with_show_node_config(self.show_node_config)
.with_silent(self.silent)
.with_system_contracts(self.dev_system_contracts)
.with_override_bytecodes_dir(self.override_bytecodes_dir.clone()) // Added
.with_log_level(self.log)
Expand Down
64 changes: 64 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ pub struct TestNodeConfig {
pub config_out: Option<String>,
/// Port the node will listen on
pub port: u16,
/// Print node config on startup if true
pub show_node_config: bool,
/// Print transactions and calls summary if true
pub show_tx_summary: bool,
/// If true, logs events.
pub show_event_logs: bool,
/// Disables printing of `console.log` invocations to stdout if true
pub disable_console_log: bool,
/// Controls visibility of call logs
pub show_calls: ShowCalls,
/// Whether to show call output data
Expand All @@ -71,6 +79,8 @@ pub struct TestNodeConfig {
pub show_gas_details: ShowGasDetails,
/// Whether to resolve hash references
pub resolve_hashes: bool,
/// Don’t print anything on startup if true
pub silent: bool,
/// Configuration for system contracts
pub system_contracts_options: system_contracts::Options,
/// Directory to override bytecodes
Expand Down Expand Up @@ -132,12 +142,17 @@ impl Default for TestNodeConfig {
// Node configuration defaults
config_out: None,
port: NODE_PORT,
show_node_config: true,
show_tx_summary: true,
show_event_logs: false,
disable_console_log: false,
show_calls: Default::default(),
show_outputs: false,
show_storage_logs: Default::default(),
show_vm_details: Default::default(),
show_gas_details: Default::default(),
resolve_hashes: false,
silent: false,
system_contracts_options: Default::default(),
override_bytecodes_dir: None,
use_evm_emulator: false,
Expand Down Expand Up @@ -192,6 +207,11 @@ impl TestNodeConfig {
)
.expect("Failed writing json");
}

if self.silent || !self.show_node_config {
return;
}

let color = CustomColor::new(13, 71, 198);

println!("{}", BANNER.custom_color(color));
Expand Down Expand Up @@ -603,6 +623,50 @@ impl TestNodeConfig {
self
}

/// Enable or disable silent mode
#[must_use]
pub fn with_silent(mut self, silent: Option<bool>) -> Self {
if let Some(silent) = silent {
self.silent = silent;
}
self
}

/// Enable or disable printing node config on startup
#[must_use]
pub fn with_show_node_config(mut self, show_node_config: Option<bool>) -> Self {
if let Some(show_node_config) = show_node_config {
self.show_node_config = show_node_config;
}
self
}

// Enable or disable printing transactions and calls summary
#[must_use]
pub fn with_show_tx_summary(mut self, show_tx_summary: Option<bool>) -> Self {
if let Some(show_tx_summary) = show_tx_summary {
self.show_tx_summary = show_tx_summary;
}
self
}
/// Enable or disable logging events
#[must_use]
pub fn with_show_event_logs(mut self, show_event_logs: Option<bool>) -> Self {
if let Some(show_event_logs) = show_event_logs {
self.show_event_logs = show_event_logs;
}
self
}

// Enable or disable printing of `console.log` invocations to stdout
#[must_use]
pub fn with_disable_console_log(mut self, disable_console_log: Option<bool>) -> Self {
if let Some(disable_console_log) = disable_console_log {
self.disable_console_log = disable_console_log;
}
self
}

/// Check if resolving hashes is enabled
pub fn is_resolve_hashes_enabled(&self) -> bool {
self.resolve_hashes
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ async fn main() -> anyhow::Result<()> {
let log_file = File::create(&config.log_file_path)?;

// Initialize the tracing subscriber
let observability =
Observability::init(vec!["era_test_node".into()], log_level_filter, log_file)?;
let observability = Observability::init(
vec!["era_test_node".into()],
log_level_filter,
log_file,
config.silent,
)?;

// Use `Command::Run` as default.
let command = command.as_ref().unwrap_or(&Command::Run);
Expand Down
40 changes: 40 additions & 0 deletions src/namespaces/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,46 @@ pub trait ConfigurationApiNamespaceT {
#[rpc(name = "config_setResolveHashes", returns = "bool")]
fn config_set_resolve_hashes(&self, value: bool) -> Result<bool>;

/// Set show_node_config for the InMemoryNodeInner
///
/// # Parameters
/// - `value`: A bool to update show_node_config to
///
/// # Returns
/// The updated/current `show_node_config` value for the InMemoryNodeInner.
#[rpc(name = "config_setShowNodeConfig", returns = "bool")]
fn config_set_show_node_config(&self, value: bool) -> Result<bool>;

/// Set show_tx_summary for the InMemoryNodeInner
///
/// # Parameters
/// - `value`: A bool to update show_tx_summary to
///
/// # Returns
/// The updated/current `show_tx_summary` value for the InMemoryNodeInner.
#[rpc(name = "config_setShowTxSummary", returns = "bool")]
fn config_set_show_tx_summary(&self, value: bool) -> Result<bool>;

/// Set show_event_logs for the InMemoryNodeInner
///
/// # Parameters
/// - `value`: A bool to update show_event_logs to
///
/// # Returns
/// The updated/current `show_event_logs` value for the InMemoryNodeInner.
#[rpc(name = "config_setShowEventLogs", returns = "bool")]
fn config_set_show_event_logs(&self, value: bool) -> Result<bool>;

/// Set disable_console_log for the InMemoryNodeInner
///
/// # Parameters
/// - `value`: A bool to update disable_console_log to
///
/// # Returns
/// The updated/current `disable_console_log` value for the InMemoryNodeInner.
#[rpc(name = "config_setDisableConsoleLog", returns = "bool")]
fn config_set_disable_console_log(&self, value: bool) -> Result<bool>;

/// Set the logging for the InMemoryNodeInner
///
/// # Parameters
Expand Down
Loading

0 comments on commit 6863404

Please sign in to comment.