Skip to content

Commit 7f65618

Browse files
committed
[Rust] Add top level documentation to tracing and logger
1 parent fa01360 commit 7f65618

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

rust/src/logger.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
// TODO: Describe this in terms of the core Logger, but refer to tracing for how to capture rust logs.
2-
1+
//! Core [`Logger`] implementation, see [`crate::tracing`] for typical plugin and headless usage.
2+
//!
3+
//! This module defines the core logger model, which is typically not used directly and instead is used
4+
//! via the [`crate::tracing`] implementations. If you require a custom [`LogListener`] or need to log
5+
//! directly to the core instead of through `tracing` macros, that is what this module is useful for.
36
use crate::file_metadata::SessionId;
47
use crate::rc::{Ref, RefCountable};
58
use crate::string::{raw_to_string, BnString, IntoCStr};

rust/src/tracing.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
// TODO: Add top level docs here.
1+
//! Integration with the [`tracing`](https://docs.rs/tracing) ecosystem. Send logs to and from Binary Ninja.
2+
//!
3+
//! This module allows you to use standard Rust `tracing` macros (like `info!`, `warn!`, `error!`)
4+
//! and have them get sent to Binary Ninja, as well as the other way around with [`TracingLogListener`].
5+
//!
6+
//! ## For Plugins
7+
//!
8+
//! When writing a plugin, and you want your Rust logs to appear in the Binary Ninja UI, use the
9+
//! [`crate::tracing_init`] macro at the start of your plugin's init function.
10+
//!
11+
//! ## For Headless
12+
//!
13+
//! When running headless (standalone executables), and you want internal Binary Ninja logs to appear
14+
//! in your terminal's standard output, register the [`TracingLogListener`] after initializing your
15+
//! tracing subscriber.
16+
//!
17+
//! ## Never use both [`BinaryNinjaLayer`] and [`TracingLogListener`] simultaneously
18+
//!
19+
//! Enabling both creates an infinite feedback loop where a log triggers a log, deadlocking the application.
220
321
use crate::file_metadata::SessionId;
422
use crate::logger::{
@@ -259,7 +277,7 @@ impl tracing::field::Visit for BnFieldVisitor {
259277
/// // Register our tracing subscriber, this will send tracing events to stdout.
260278
/// tracing_subscriber::fmt::init();
261279
/// // Register our log listener, this will send logs from the core to our tracing subscriber.
262-
/// let _listener = TracingLogListener::new(BnLogLevel::DebugLog).register();
280+
/// let _listener = TracingLogListener::new().register();
263281
/// // Should see logs from the core in regard to initialization show up.
264282
/// let _session = Session::new().expect("Failed to create session");
265283
/// bn_log("Test", BnLogLevel::DebugLog, "Hello, world!");

0 commit comments

Comments
 (0)