Skip to content

Commit 1515cc5

Browse files
committed
enable tracing in libzkp
1 parent 59b0f11 commit 1515cc5

File tree

6 files changed

+42
-2
lines changed

6 files changed

+42
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coordinator/internal/logic/libzkp/lib.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import (
1717
"scroll-tech/common/types/message"
1818
)
1919

20+
func init() {
21+
C.init_tracing()
22+
}
23+
2024
// Helper function to convert Go string to C string and handle cleanup
2125
func goToCString(s string) *C.char {
2226
return C.CString(s)

coordinator/internal/logic/libzkp/libzkp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
#include <stddef.h> // For size_t
1010

11+
// Init log tracing
12+
void init_tracing();
13+
1114
// Initialize the verifier with configuration
1215
void init_verifier(char* config);
1316

crates/libzkp/src/tasks/chunk_task.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

crates/libzkp_c/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
libzkp = { path = "../libzkp" }
1313
l2geth = { path = "../l2geth"}
14+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
1415
tracing.workspace = true

crates/libzkp_c/src/lib.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,37 @@ use std::ffi::{c_char, CString};
55
use libzkp::TaskType;
66
use utils::{c_char_to_str, c_char_to_vec};
77

8+
use std::sync::OnceLock;
9+
10+
static LOG_SETTINGS: OnceLock<Result<(), String>> = OnceLock::new();
11+
12+
/// # Safety
13+
#[no_mangle]
14+
pub unsafe extern "C" fn init_tracing() {
15+
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
16+
17+
LOG_SETTINGS
18+
.get_or_init(|| {
19+
tracing_subscriber::fmt()
20+
.with_env_filter(
21+
EnvFilter::builder()
22+
.with_default_directive(LevelFilter::INFO.into())
23+
.from_env_lossy(),
24+
)
25+
.with_ansi(false)
26+
.with_level(true)
27+
.with_target(true)
28+
.try_init()
29+
.map_err(|e| format!("{e}"))?;
30+
31+
Ok(())
32+
})
33+
.clone()
34+
.expect("Failed to initialize tracing subscriber");
35+
36+
tracing::info!("Tracing has been initialized normally");
37+
}
38+
839
/// # Safety
940
#[no_mangle]
1041
pub unsafe extern "C" fn init_verifier(config: *const c_char) {
@@ -136,8 +167,7 @@ pub unsafe extern "C" fn gen_universal_task(
136167
expected_pi_hash,
137168
}
138169
} else {
139-
println!("gen_universal_task, error: {:#}", ret.unwrap_err());
140-
//tracing::error!("gen_universal_task failed, error: {:#}", ret.unwrap_err());
170+
tracing::error!("gen_universal_task failed, error: {:#}", ret.unwrap_err());
141171
failed_handling_result()
142172
}
143173
}

0 commit comments

Comments
 (0)