TracingLogListener

Struct TracingLogListener 

Source
pub struct TracingLogListener { /* private fields */ }
Expand description

A LogListener that forwards logs to the registered [Subscriber].

This should never be registered if the BinaryNinjaLayer is active. The BinaryNinjaLayer will consume our events we send in this log listener and send them back to the core, causing a never-ending cycle of sending and receiving the same logs.

Typically, you will register this listener for headless applications. You can technically use this in a plugin, but it is likely that you are sending tracing logs to the core, in which case you will run into the problem above.

use binaryninja::tracing::TracingLogListener;
use binaryninja::logger::{register_log_listener, BnLogLevel, bn_log};
use binaryninja::headless::Session;

pub fn main() {
    // Register our tracing subscriber, this will send tracing events to stdout.
    tracing_subscriber::fmt::init();
    // Register our log listener, this will send logs from the core to our tracing subscriber.
    let _listener = TracingLogListener::new().register();
    // Should see logs from the core in regard to initialization show up.
    let _session = Session::new().expect("Failed to create session");
    bn_log("Test", BnLogLevel::DebugLog, "Hello, world!");
}

Implementations§

Source§

impl TracingLogListener

Source

pub fn new() -> Self

Create a TracingLogListener with the minimum log level set to BnLogLevel::InfoLog.

Source

pub fn new_with_lvl(minimum_level: BnLogLevel) -> Self

Source

pub fn register(self) -> LogGuard<Self>

Register the TracingLogListener and send logs to the registered tracing subscriber until the LogGuard is dropped, make sure to register your tracing subscriber before registering.

Trait Implementations§

Source§

impl Default for TracingLogListener

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl LogListener for TracingLogListener

Source§

fn log(&self, ctx: &LogContext<'_>, level: BnLogLevel, message: &str)

Called when a log message is received from the core. Read more
Source§

fn level(&self) -> BnLogLevel

The desired minimum log level, any logs below this level will be ignored. Read more
Source§

fn close(&self)

Called when the listener is unregistered.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more