libsir 2.2.6
Standard Incident Reporter
|
Functions | |
PLUGIN_EXPORT bool | sir_plugin_query (sir_plugininfo *info) |
Called by libsir after the plugin library object is loaded, but before any other functions are probed or called. | |
PLUGIN_EXPORT bool | sir_plugin_init (void) |
Called by libsir after the plugin is queried and successfully validated. | |
PLUGIN_EXPORT bool | sir_plugin_write (sir_level level, const char *message) |
Called by libsir when a message is dispatched on any level whose bit was set in the levels bitmask of the sir_plugininfo structure when sir_plugin_query was called. | |
PLUGIN_EXPORT bool | sir_plugin_cleanup (void) |
Called by libsir when the plugin is about to be unloaded. | |
Using plugins, it is possible to extend libsir's reach when dispatching log messages. A simple example of this would be a plugin that only registers for emergency-level messages. Whenever it receives a message, it posts the message to a REST API endpoint which results in a push notification being sent to a mobile device.
Use your imagination; essentially anything is possible. There are some caveats, though: until the thread pool and job queue mechanisms implemented in (#121) are utilized, plugins must either only perform operations that are guaranteed to complete quickly, or perform those operations asynchronously (i.e., on another thread).
libsir's plugin interface will be versioned; the functions appearing on this page comprise the plugin interface v1. If/when a new function export is added (or one is modified), the version number will be bumped.
When plugins are compiled, their interface version is hard-coded in. This means that as libsir continues to evolve (and the version number increases), it can still communicate with older plugins via backwards-compatible versioned interfaces.
The following steps should be taken in order to write your own fully- functioning libsir plugin:
plugins/sample
directory (within plugins
).cd
back into the root directory of the repository and run make clean plugins
. If everything goes smoothly, your shiny new plugin should now be located in build/lib
. If you named your directory 'foo', you should see a plugin_foo.[so/dll]
.If you encounter any problems, rebuild with env SIR_SELFLOG=1 SIR_DEBUG=1 make clean plugins
. This will enable diagnostic output from libsir that should aid in the diagnosis of any issues you encounter. If you're still stuck, reach out and somebody will assist you within a reasonable amount of time.
PLUGIN_EXPORT bool sir_plugin_cleanup | ( | void | ) |
Called by libsir when the plugin is about to be unloaded.
The plugin should immediately begin releasing allocated resources and resetting its internal state.
true
if the plugin cleaned up successfully, false
otherwise. PLUGIN_EXPORT bool sir_plugin_init | ( | void | ) |
Called by libsir after the plugin is queried and successfully validated.
The plugin should only at the time of this call begin allocating resources and initializing its internal state.
true
if the plugin successfully initialized its internal state, false
otherwise. PLUGIN_EXPORT bool sir_plugin_query | ( | sir_plugininfo * | info | ) |
Called by libsir after the plugin library object is loaded, but before any other functions are probed or called.
The plugin must fill out the information in the info
structure in a way satisfactory to libsir, or it will immediately be unloaded:
iface_ver
must be set to SIR_PLUGIN_VCURRENT
.char*
members must be set to valid strings, and must point at static memory that will not go out of scope when the function exits. Do not allocate heap memory for these properties; they will be leaked.levels
must be a valid sir_level bitmask.opts
must be a valid sir_option bitmask.info | Pointer to a sir_plugininfo structure to be initialized by the plugin. |
true
if the info
structure was successfully initialized, false
otherwise. If false
, the plugin will be unloaded. PLUGIN_EXPORT bool sir_plugin_write | ( | sir_level | level, |
const char * | message ) |
Called by libsir when a message is dispatched on any level whose bit was set in the levels
bitmask of the sir_plugininfo structure when sir_plugin_query was called.
The message
string will be pre-formatted according to the sir_option set in the opts
bitmask of the sir_plugininfo structure.
level | The sir_level of the message being dispatched. |
message | A string containing the pre-formatted message being dispatched. |
true
if the message was successfully processed, false
otherwise.