Skip to content

Commit

Permalink
refactor: enable verbose tracing for Debug profile
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Dec 31, 2023
1 parent e500da2 commit 3e7e715
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ option(USE_VALGRIND "Use valgrind when testing" true)
option(WITH_RUST "Use rust implemented internals (experimental)" false)
if (WITH_RUST)
add_subdirectory(cmake/corrosion)
corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES chewing FEATURES capi)
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES chewing FEATURES capi test-tracing)
else()
corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES chewing FEATURES capi)
endif()
corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES chewing-tools)
add_compile_definitions(WITH_RUST)
endif()
Expand Down
146 changes: 146 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ tracing = { version = "0.1.40", features = [
"max_level_trace",
"release_max_level_warn",
] }
tracing-subscriber = { version = "0.3.18", features = [
"env-filter",
], optional = true }

[target.'cfg(windows)'.dependencies]
rusqlite = { version = "0.30.0", features = ["bundled"] }
Expand All @@ -30,6 +33,7 @@ crate-type = ["lib", "staticlib"]
[features]
default = []
capi = ["cbindgen"]
test-tracing = ["tracing-subscriber"]

[build-dependencies]
# https://github.com/mozilla/cbindgen/issues/891
Expand Down
3 changes: 2 additions & 1 deletion src/capi/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ pub extern "C" fn chewing_set_logger(
logger: extern "C" fn(data: *mut c_void, level: c_int, fmt: *const c_char, arg: ...),
data: *mut c_void,
) {
// let _ = tracing_subscriber::fmt::try_init();
#[cfg(all(feature = "test-tracing", debug_assertions))]
let _ = tracing_subscriber::fmt::try_init();
}

#[tracing::instrument(skip(ctx), ret)]
Expand Down

0 comments on commit 3e7e715

Please sign in to comment.