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
impl LogCallbackManager
Sourcepub fn global() -> &'static LogCallbackManager
pub fn global() -> &'static LogCallbackManager
Get the global callback manager instance
Sourcepub fn set_callback(&self, callback: Option<LogCallback>)
pub fn set_callback(&self, callback: Option<LogCallback>)
Set the log callback
Sourcepub fn register_plugin(&self, callback: Option<LogCallback>)
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.
Sourcepub fn unregister_plugin(&self)
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.
Sourcepub fn plugin_count(&self) -> usize
pub fn plugin_count(&self) -> usize
Get the current reference count (number of active plugins)
Sourcepub fn get_callback(&self) -> Option<LogCallback>
pub fn get_callback(&self) -> Option<LogCallback>
Get the current log callback
Sourcepub fn is_enabled(&self, level: LogLevel) -> bool
pub fn is_enabled(&self, level: LogLevel) -> bool
Check if a log level is enabled