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:
If you encounter problems, rebuild libsir and your plugin with internal diagnostics enabled: env SIR_SELFLOG=1 SIR_DEBUG=1 make clean all.
Ideally, the additional output from the innards of libsir will aid in the diagnosis and resolution of any potential hangups.
| 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.
| 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.
| 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:
| info | Pointer to a sir_plugininfo structure to be initialized by the plugin. |
| 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. |