Skip to content

Commit

Permalink
Add debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Diane Huxley committed Aug 15, 2024
1 parent 8350fc2 commit d7558e4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
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"
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! {
pub(crate) static ref LOG_LEVEL: Option<String> = {
std::env::var("WEB5_SDK_LOG_LEVEL").ok()
};
}

pub(crate) mod logging {
#[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);
}
}
};
}
}

0 comments on commit d7558e4

Please sign in to comment.