Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug logging #285

Closed
wants to merge 17 commits into from
3 changes: 3 additions & 0 deletions .github/workflows/build-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- main
pull_request:

env:
WEB5_SDK_LOG_LEVEL: debug

jobs:
build_aarch64_apple_darwin:
runs-on: macos-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
CARGO_TERM_COLOR: always
# Make sure CI fails on all warnings, including Clippy lints
RUSTFLAGS: "-Dwarnings"
WEB5_SDK_LOG_LEVEL: debug

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions crates/web5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ josekit = "0.8.6"
jsonpath-rust = "0.5.1"
jsonschema = { version = "0.18.0", default-features = false }
k256 = { version = "0.13.3", features = ["ecdsa", "jwk"] }
lazy_static = "1.5.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update the Justfile to 1.80.0 and use the new LazyLock? I'm doing that over here https://github.com/TBD54566975/web5-rs/pull/283/files#diff-8b2fda406bc73cf365197448d20bd9ea1d05db17e9b8dca69881ad9dd9755f5d (scroll down to the tests)

tokio = "1.38.0"
rand = { workspace = true }
regex = "1.10.4"
Expand Down
27 changes: 27 additions & 0 deletions crates/web5/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,30 @@ pub mod dids;

#[cfg(test)]
mod test_helpers;

lazy_static::lazy_static! {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use the LazyLock or LazyCell here and then remove the addition of lazy_static in the Cargo.toml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upd8d

pub(crate) static ref LOG_LEVEL: Option<String> = {
std::env::var("WEB5_SDK_LOG_LEVEL").ok()
};
}

pub(crate) mod logging {
KendallWeihe marked this conversation as resolved.
Show resolved Hide resolved
#[macro_export]
macro_rules! log_dbg {
($msg:expr, $($arg:tt)*) => {
if let Some(ref level) = *$crate::LOG_LEVEL {
if level == "DEBUG" {
println!("[DEBUG] {}", format!($msg, $($arg)*));
}
}
};
($closure:expr) => {
if let Some(ref level) = *$crate::LOG_LEVEL {
if level == "DEBUG" {
let msg = $closure();
println!("[DEBUG] {}", msg);
}
}
};
}
}
Loading