Skip to content

Conversation

@emesare
Copy link
Member

@emesare emesare commented Dec 18, 2025

  • Added more documentation
  • Replaced global named logger for plugins, fixing the issue when the CU has multiple (e.g. statically linked demo)
  • Explicitly name the target for the log event, this is how it must be done to guarantee we send it to the correct one
  • Simplified some misc code
  • Added session_id event field, to send logs to a particular session (e.g. binary view scoped logs)

This is a breaking change, but I believe there is no better time to make it, we cannot continue to use the log crate, it is too limited for our needs.

Still need to finish docs and cross link more between the logger module and the tracing module, as well as provide some examples in the top level module docs.

Still need to place more session id spans in relevant callbacks so that they automatically get scoped to a bv.

TBD if we keep the tracing re-exports for the macros, we might instead let callers use the non re-exported version. or we might move the code into logger and then re-export tracing at the top level, or we might not re-export at all and assume the caller includes tracing in Cargo.toml.

@emesare emesare added the Component: Rust API Issue needs changes to the Rust API label Dec 18, 2025
@emesare
Copy link
Member Author

emesare commented Dec 18, 2025

Resolves #6863

@emesare emesare linked an issue Dec 18, 2025 that may be closed by this pull request
- Added more documentation
- Replaced global named logger for plugins, fixing the issue when the CU has multiple (e.g. statically linked demo)
- Simplified some misc code

This is a breaking change, but I believe there is no better time to make it, we cannot continue to use the `log` crate, it is too limited for our needs.
@emesare
Copy link
Member Author

emesare commented Dec 18, 2025

Force pushed removing explicit targets in log calls, replaced with rewrite rules within the registered tracing BinaryNinjaLayer

@emesare
Copy link
Member Author

emesare commented Dec 20, 2025

Migration guide:

  1. Add/Remove crates:
diff --git a/plugins/pdb-ng/Cargo.toml b/plugins/pdb-ng/Cargo.toml
--- a/plugins/pdb-ng/Cargo.toml
+++ b/plugins/pdb-ng/Cargo.toml
@@ -16,1 +16,2 @@
 regex = "1"
+tracing = "0.1"
  1. Replace usage of log helper macros:
diff --git a/plugins/warp/src/plugin/load.rs b/plugins/warp/src/plugin/load.rs
--- a/plugins/warp/src/plugin/load.rs
+++ b/plugins/warp/src/plugin/load.rs
@@ -132,4 +133,4 @@
             Err(e) => {
-                log::error!("Failed to read signature file: {}", e);
+                tracing::error!("Failed to read signature file: {}", e);
                 return;
             }

You can technically keep using log::info! and friends, see tracing documentation for more details.

  1. Replace Logger::new at top of plugin init with tracing_init!:
diff --git a/plugins/pdb-ng/src/lib.rs b/plugins/pdb-ng/src/lib.rs
--- a/plugins/pdb-ng/src/lib.rs
+++ b/plugins/pdb-ng/src/lib.rs
@@ -721,1 +729,1 @@
-    Logger::new("PDB").init();
+    binaryninja::tracing_init!("PDB Import");

@emesare emesare marked this pull request as ready for review December 20, 2025 01:09
@emesare emesare requested a review from bdash December 20, 2025 01:09
@emesare emesare added this to the Jotunheim milestone Dec 20, 2025
Assign the `session_id` span field before calling into the relocation handler so logs get scoped to the specific view.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Rust API Issue needs changes to the Rust API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Rust API] Improve logger documentation

2 participants