Skip to main content

LogCallbackManager

Struct LogCallbackManager 

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

Manager for FFI log callbacks

Each plugin can register its own log callback. The callback is cleared when the plugin that registered it shuts down to prevent use-after-free (the callback function pointer is tied to the plugin’s FFI arena lifetime).

Log level is shared globally and persists across plugin reload cycles.

Implementations§

Source§

impl LogCallbackManager

Source

pub fn new() -> Self

Create a new callback manager

Source

pub fn global() -> &'static LogCallbackManager

Get the global callback manager instance

Source

pub fn set_callback(&self, callback: Option<LogCallback>)

Set the log callback

Source

pub fn register_plugin(&self, callback: Option<LogCallback>)

Register a plugin with the callback manager

This increments the reference count and optionally sets the callback. If a callback is provided, it replaces any existing callback.

Important: The callback function pointer is tied to the plugin’s FFI arena lifetime. When the plugin shuts down, the callback becomes invalid and must be cleared before the arena is closed.

This should be called during plugin initialization.

Source

pub fn unregister_plugin(&self)

Unregister a plugin from the callback manager

Critical: This ALWAYS clears the callback to prevent use-after-free. The callback function pointer is tied to the plugin’s FFI arena, which will be closed immediately after this function returns. If we didn’t clear the callback, any subsequent logging would call an invalid pointer.

This means that with multiple plugins, the last one to unregister will disable logging for any remaining plugins until they re-register a callback. This is a safety trade-off: we prioritize crash prevention over convenience.

Note: The reload handle is NOT cleared because logging initialization only happens once per process. The reload handle must persist across plugin reload cycles.

This should be called during plugin shutdown.

Source

pub fn plugin_count(&self) -> usize

Get the current reference count (number of active plugins)

Source

pub fn get_callback(&self) -> Option<LogCallback>

Get the current log callback

Source

pub fn set_level(&self, level: LogLevel)

Set the log level

Source

pub fn level(&self) -> LogLevel

Get the current log level

Source

pub fn is_enabled(&self, level: LogLevel) -> bool

Check if a log level is enabled

Source

pub fn log(&self, level: LogLevel, target: &str, message: &str)

Invoke the callback if set and level is enabled

§Safety

The callback must be a valid function pointer that follows the LogCallback signature contract.

Trait Implementations§

Source§

impl Default for LogCallbackManager

Source§

fn default() -> Self

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

impl Send for LogCallbackManager

Source§

impl Sync for LogCallbackManager

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.

Source§

impl<T> Instrument for T

Source§

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

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

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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