Skip to content

Commit

Permalink
feat: add support for writing tracing debug info to file (#3790)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Turning rtacing on/off by adding code each time is cumbersome.

## Summary\*

Allows to turn tracing on by defining `env` `NARGO_LOG_DIR` =
`/path/to/directory/with/logs/`

Our own tracing would be aded gradually on as needed basis. By enabling
this we still benefit from other crates using tracing.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: Tom French <[email protected]>
  • Loading branch information
kobyhallx and TomAFrench authored Dec 14, 2023
1 parent 97373e8 commit 98a5004
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
72 changes: 63 additions & 9 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ num-traits = "0.2"
similar-asserts = "1.5.0"
log = "0.4.17"

tracing = "0.1.40"

[profile.dev]
# This is required to be able to run `cargo test` in acvm_js due to the `locals exceeds maximum` error.
# See https://ritik-mishra.medium.com/resolving-the-wasm-pack-error-locals-exceed-maximum-ec3a9d96685b
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"acir",
"acvm",
"aeiou",
"appender",
"arithmetization",
"arity",
"arkworks",
Expand Down
5 changes: 5 additions & 0 deletions tooling/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ tokio = { version = "1.0", features = ["io-std"] }
backend-interface = { path = "../backend_interface" }
bb_abstraction_leaks.workspace = true

# Logs
tracing.workspace = true
tracing-subscriber = "0.3.18"
tracing-appender = "0.2.3"

[target.'cfg(not(unix))'.dependencies]
tokio-util = { version = "0.7.8", features = ["compat"] }

Expand Down
13 changes: 13 additions & 0 deletions tooling/nargo_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,28 @@ mod backends;
mod cli;
mod errors;

use std::env;

use color_eyre::config::HookBuilder;
use env_logger::{Builder, Env};
use tracing_appender::rolling;

const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml";

fn main() {
let env = Env::default().filter_or("NOIR_LOG", "error"); // Default to 'error' if NOIR_LOG is not set
Builder::from_env(env).init();

// Setup tracing
if let Ok(log_dir) = env::var("NARGO_LOG_DIR") {
let debug_file = rolling::daily(log_dir, "nargo-log");
tracing_subscriber::fmt()
.with_writer(debug_file)
.with_ansi(false)
.with_max_level(tracing::Level::TRACE)
.init();
}

// Register a panic hook to display more readable panic messages to end-users
let (panic_hook, _) =
HookBuilder::default().display_env_section(false).panic_section(PANIC_MESSAGE).into_hooks();
Expand Down

0 comments on commit 98a5004

Please sign in to comment.