libsir 2.2.5
Standard Incident Reporter
|
Functions | |
bool | sir_makeinit (sirinit *si) |
Fills out a sirinit structure with default values. | |
bool | sir_init (sirinit *si) |
Initializes libsir for use. | |
bool | sir_cleanup (void) |
Tears down and cleans up libsir after use. | |
bool | sir_isinitialized (void) |
Determines whether or not libsir is in the initialized state. | |
uint16_t | sir_geterror (char message[SIR_MAXERROR]) |
Retrieves a formatted message for the last error that occurred on the calling thread and returns the associated error code. | |
void | sir_geterrorinfo (sir_errorinfo *err) |
Retrieves granular information about the last error that occurred on the calling thread. | |
bool | sir_debug (PRINTF_FORMAT const char *format,...) |
Dispatches a SIRL_DEBUG level message. | |
bool | sir_info (PRINTF_FORMAT const char *format,...) |
Dispatches a SIRL_INFO level message. | |
bool | sir_notice (PRINTF_FORMAT const char *format,...) |
Dispatches a SIRL_NOTICE level message. | |
bool | sir_warn (PRINTF_FORMAT const char *format,...) |
Dispatches a SIRL_WARN level message. | |
bool | sir_error (PRINTF_FORMAT const char *format,...) |
Dispatches a SIRL_ERROR level message. | |
bool | sir_crit (PRINTF_FORMAT const char *format,...) |
Dispatches a SIRL_CRIT level message. | |
bool | sir_alert (PRINTF_FORMAT const char *format,...) |
Dispatches a SIRL_ALERT level message. | |
bool | sir_emerg (PRINTF_FORMAT const char *format,...) |
Dispatches a SIRL_EMERG level message. | |
sirfileid | sir_addfile (const char *path, sir_levels levels, sir_options opts) |
Adds a log file and registers it to receive log output. | |
bool | sir_remfile (sirfileid id) |
Removes a file previously added to libsir. | |
sirpluginid | sir_loadplugin (const char *path) |
Loads a plugin module from disk. | |
bool | sir_unloadplugin (sirpluginid id) |
Unloads a previously registered plugin module. | |
bool | sir_filelevels (sirfileid id, sir_levels levels) |
Set new level registrations for a log file already managed by libsir. | |
bool | sir_fileopts (sirfileid id, sir_options opts) |
Set new formatting options for a log file already managed by libsir. | |
bool | sir_settextstyle (sir_level level, sir_textattr attr, sir_textcolor fg, sir_textcolor bg) |
Set new text styling for stdio (stdout/stderr) destinations on a per-level basis. | |
bool | sir_resettextstyles (void) |
Reset text styling for stdio (stdout/stderr) destinations to their default values. | |
sir_textcolor | sir_makergb (sir_textcolor r, sir_textcolor g, sir_textcolor b) |
Creates a sir_textcolor from red, green, and blue components. | |
bool | sir_setcolormode (sir_colormode mode) |
Sets the ANSI color mode for stdio destinations. | |
bool | sir_stdoutlevels (sir_levels levels) |
Set new level registrations for stdout . | |
bool | sir_stdoutopts (sir_options opts) |
Set new formatting options for stdout . | |
bool | sir_stderrlevels (sir_levels levels) |
Set new level registrations for stderr . | |
bool | sir_stderropts (sir_options opts) |
Set new formatting options for stderr . | |
bool | sir_sysloglevels (sir_levels levels) |
Set new level registrations for the system logger destination. | |
bool | sir_syslogopts (sir_options opts) |
Set new formatting options for the system logger destination. | |
bool | sir_syslogid (const char *identity) |
Set new system logger identity. | |
bool | sir_syslogcat (const char *category) |
Set new system logger category. | |
const char * | sir_getversionstring (void) |
Returns the current libsir version as a string. | |
uint32_t | sir_getversionhex (void) |
Returns the current libsir version as a number. | |
bool | sir_isprerelease (void) |
Whether or not this is a pre-release version of libsir. | |
sirfileid sir_addfile | ( | const char * | path, |
sir_levels | levels, | ||
sir_options | opts ) |
Adds a log file and registers it to receive log output.
The file at path
will be created if it does not exist, otherwise it will be appended to.
The levels for which the file will receive output are specified in the levels
bitmask. If you wish to use the default levels, pass SIRL_DEFAULT.
The formatting options for the log output sent to the file are specified in the opts
bitmask. If you wish to use the default options, pass SIRO_DEFAULT. By default, log files receive all available information.
path
is a relative path, it shall be treated as relative to the current working directory. This is not necessarily the same directory that your application's binary file resides in.path | The absolute or relative path of the file to become a logging destination for libsir. |
levels | Level registration bitmask. |
opts | Formatting options bitmask. |
bool sir_alert | ( | PRINTF_FORMAT const char * | format, |
... ) |
Dispatches a SIRL_ALERT level message.
The message will be delivered to all destinations registered to receive alert-level messages, each with their own formatting and styling options.
stdout
/stderr
, call sir_stdoutopts/sir_stdoutlevels and sir_stderropts/sir_stderrlevels, respectively. To change the text styling on a per-level basis, call sir_settextstyle.format | A printf-style format string, representing the template for the message to dispatch. |
... | Arguments whose type and position align with the format specifiers in format . |
true
if the message was dispatched successfully to all registered destinations, false
otherwise. Call sir_geterror to obtain information about any error that may have occurred. bool sir_cleanup | ( | void | ) |
Tears down and cleans up libsir after use.
Deallocates resources such as memory buffers, file descriptors, etc. and resets the internal state. No calls into libsir will succeed after calling sir_cleanup (with the exception of sir_makeinit, sir_init, sir_isinitialized,sir_geterror, and sir_geterrorinfo).
May be called from any thread. If you wish to utilize libsir again during the same process' lifetime, simply call sir_init again.
true
if cleanup was successful, false otherwise
. Call sir_geterror to obtain information about any error that may have occurred. bool sir_crit | ( | PRINTF_FORMAT const char * | format, |
... ) |
Dispatches a SIRL_CRIT level message.
The message will be delivered to all destinations registered to receive critical-level messages, each with their own formatting and styling options.
stdout
/stderr
, call sir_stdoutopts/sir_stdoutlevels and sir_stderropts/sir_stderrlevels, respectively. To change the text styling on a per-level basis, call sir_settextstyle.format | A printf-style format string, representing the template for the message to dispatch. |
... | Arguments whose type and position align with the format specifiers in format . |
true
if the message was dispatched successfully to all registered destinations, false
otherwise. Call sir_geterror to obtain information about any error that may have occurred. bool sir_debug | ( | PRINTF_FORMAT const char * | format, |
... ) |
Dispatches a SIRL_DEBUG level message.
The message will be delivered to all destinations registered to receive debug-level messages, each with their own formatting and styling options.
stdout
/stderr
, call sir_stdoutopts/sir_stdoutlevels and sir_stderropts/sir_stderrlevels, respectively. To change the text styling on a per-level basis, call sir_settextstyle.format | A printf-style format string, representing the template for the message to dispatch. |
... | Arguments whose type and position align with the format specifiers in format . |
true
if the message was dispatched successfully to all registered destinations, false
otherwise. Call sir_geterror to obtain information about any error that may have occurred. bool sir_emerg | ( | PRINTF_FORMAT const char * | format, |
... ) |
Dispatches a SIRL_EMERG level message.
The message will be delivered to all destinations registered to receive emergency-level messages, each with their own formatting and styling options.
stdout
/stderr
, call sir_stdoutopts/sir_stdoutlevels and sir_stderropts/sir_stderrlevels, respectively. To change the text styling on a per-level basis, call sir_settextstyle.format | A printf-style format string, representing the template for the message to dispatch. |
... | Arguments whose type and position align with the format specifiers in format . |
true
if the message was dispatched successfully to all registered destinations, false
otherwise. Call sir_geterror to obtain information about any error that may have occurred. bool sir_error | ( | PRINTF_FORMAT const char * | format, |
... ) |
Dispatches a SIRL_ERROR level message.
The message will be delivered to all destinations registered to receive error-level messages, each with their own formatting and styling options.
stdout
/stderr
, call sir_stdoutopts/sir_stdoutlevels and sir_stderropts/sir_stderrlevels, respectively. To change the text styling on a per-level basis, call sir_settextstyle.format | A printf-style format string, representing the template for the message to dispatch. |
... | Arguments whose type and position align with the format specifiers in format . |
true
if the message was dispatched successfully to all registered destinations, false
otherwise. Call sir_geterror to obtain information about any error that may have occurred. bool sir_filelevels | ( | sirfileid | id, |
sir_levels | levels ) |
Set new level registrations for a log file already managed by libsir.
By default, log files are registered for the following levels:
id | The sirfileid obtained when the file was added to libsir. |
levels | New bitmask of sir_level to register for. If you wish to use the default levels, pass SIRL_DEFAULT. |
true
if the file is known to libsir and was successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_fileopts | ( | sirfileid | id, |
sir_options | opts ) |
Set new formatting options for a log file already managed by libsir.
By default, log files have the following formatting options:
id | The sirfileid obtained when the file was added to libsir. |
opts | New bitmask of sir_option for the file. If you wish to use the default options, pass SIRO_DEFAULT. |
true
if the file is known to libsir and was successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. uint16_t sir_geterror | ( | char | message[SIR_MAXERROR] | ) |
Retrieves a formatted message for the last error that occurred on the calling thread and returns the associated error code.
To retrieve more granular information about an error, or to customize the error message format, use sir_geterrorinfo.
message | A buffer of SIR_MAXERROR chars into which the error message is placed. |
void sir_geterrorinfo | ( | sir_errorinfo * | err | ) |
Retrieves granular information about the last error that occurred on the calling thread.
To retrieve just an error code and a formatted message, use sir_geterror.
err | Pointer to a sir_errorinfo structure into which the error infor- mation is placed. |
uint32_t sir_getversionhex | ( | void | ) |
Returns the current libsir version as a number.
const char * sir_getversionstring | ( | void | ) |
Returns the current libsir version as a string.
Example:
bool sir_info | ( | PRINTF_FORMAT const char * | format, |
... ) |
Dispatches a SIRL_INFO level message.
The message will be delivered to all destinations registered to receive information-level messages, each with their own formatting and styling options.
stdout
/stderr
, call sir_stdoutopts/sir_stdoutlevels and sir_stderropts/sir_stderrlevels, respectively. To change the text styling on a per-level basis, call sir_settextstyle.format | A printf-style format string, representing the template for the message to dispatch. |
... | Arguments whose type and position align with the format specifiers in format . |
true
if the message was dispatched successfully to all registered destinations, false
otherwise. Call sir_geterror to obtain information about any error that may have occurred. bool sir_init | ( | sirinit * | si | ) |
Initializes libsir for use.
Must be called before making any other calls into libsir (with the exception of sir_makeinit).
For every call to sir_init, there must be a corresponding call to sir_cleanup. All exported libsir functions are thread-safe, so you may initialize and cleanup on whichever thread you wish.
si | Pointer to a sirinit structure containing the desired settings and configuration. libsir makes a copy of this structure, so its lifetime is not a concern. |
true
if initialization was successful, false
otherwise. Call sir_geterror to obtain information about any error that may have occurred. bool sir_isinitialized | ( | void | ) |
Determines whether or not libsir is in the initialized state.
Provided as a convenience method to detect whether libsir requires initial- ization or cleanup at any given time.
true
if sir_init has been called and libsir is initialized; false
if sir_init has not yet been called, or a corresponding call to sir_cleanup has already been made. bool sir_isprerelease | ( | void | ) |
Whether or not this is a pre-release version of libsir.
true
if this is a pre-release version of libsir (i.e., not a public release), false
if this is a public release version. sirpluginid sir_loadplugin | ( | const char * | path | ) |
Loads a plugin module from disk.
Loads, queries, validates, and initializes a libsir plugin module. If loading and validation are successful, the plugin is registered in the internal cache.
After that point in time, the plugin will be notified upon the dispatching of log messages on any sir_level the plugin registered for when it was loaded.
path
is a relative path, it shall be treated as relative to the current working directory. This is not necessarily the same directory that your application's binary file resides in.path | The absolute or relative path of the plugin to be loaded and registered. |
bool sir_makeinit | ( | sirinit * | si | ) |
Fills out a sirinit structure with default values.
Creates an initialization configuration for libsir essentially using all of the default values (i.e., level registrations, formatting options, and text styling).
si | Pointer to a sirinit structure to receive default values. |
true
if si
is not NULL
, false
otherwise. sir_textcolor sir_makergb | ( | sir_textcolor | r, |
sir_textcolor | g, | ||
sir_textcolor | b ) |
Creates a sir_textcolor from red, green, and blue components.
r | The red component (0..255) |
g | The green component (0..255) |
b | The blue component (0..255) |
bool sir_notice | ( | PRINTF_FORMAT const char * | format, |
... ) |
Dispatches a SIRL_NOTICE level message.
The message will be delivered to all destinations registered to receive notice-level messages, each with their own formatting and styling options.
stdout
/stderr
, call sir_stdoutopts/sir_stdoutlevels and sir_stderropts/sir_stderrlevels, respectively. To change the text styling on a per-level basis, call sir_settextstyle.format | A printf-style format string, representing the template for the message to dispatch. |
... | Arguments whose type and position align with the format specifiers in format . |
true
if the message was dispatched successfully to all registered destinations, false
otherwise. Call sir_geterror to obtain information about any error that may have occurred. bool sir_remfile | ( | sirfileid | id | ) |
Removes a file previously added to libsir.
Immediately causes the file represented by id
(the value returned from sir_addfile) to be removed from libsir, and its file descriptor closed.
Its contents will remain intact, and any pending writes will be flushed to the file before it is closed.
id | The sirfileid obtained when the file was added to libsir. |
true
if the file is known to libsir and was successfully removed, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_resettextstyles | ( | void | ) |
Reset text styling for stdio (stdout/stderr) destinations to their default values.
true
if successfully reset, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_setcolormode | ( | sir_colormode | mode | ) |
Sets the ANSI color mode for stdio destinations.
The available modes are:
SIRCM_16
: 4-bit, 16-color mode. Colors are defined by the SIRTC_*
values. This is the default mode.SIRCM_256
: 8-bit, 256-color mode. Colors are defined by numeric value (0..255)SIRCM_RGB
: 24-bit RGB color mode. Colors are defined by numeric value, with red, green, and blue components (0..255) each.mode | One of the SIRCM_* constants, defining the mode to use. |
true
if the color mode was changed successfully, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_settextstyle | ( | sir_level | level, |
sir_textattr | attr, | ||
sir_textcolor | fg, | ||
sir_textcolor | bg ) |
Set new text styling for stdio (stdout/stderr) destinations on a per-level basis.
SIRTC_DEFAULT
to get the default foreground or background color. To set colors in RGB color mode, use sir_makergb to create the foreground and background colors.level | The sir_level for which to set the text styling. |
attr | The sir_textattr attributes to apply to the text. |
fg | The foreground color to apply to the text. |
bg | The background color to apply to the text. |
true
if successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_stderrlevels | ( | sir_levels | levels | ) |
Set new level registrations for stderr
.
By default, stderr
is registered for the following levels:
To modify formatting options for stderr
, use sir_stderropts.
levels | New bitmask of sir_level to register for. If you wish to use the default levels, pass SIRL_DEFAULT. |
true
if successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_stderropts | ( | sir_options | opts | ) |
Set new formatting options for stderr
.
By default, stderr
has the following formatting options:
To modify level registrations for stderr
, use sir_stderrlevels.
opts | New bitmask of sir_option for stderr . If you wish to use the default values, pass SIRL_DEFAULT. |
true
if successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_stdoutlevels | ( | sir_levels | levels | ) |
Set new level registrations for stdout
.
By default, stdout
is registered for the following levels:
To modify formatting options for stdout
, use sir_stdoutopts.
levels | New bitmask of sir_level to register for. If you wish to use the default levels, pass SIRL_DEFAULT. |
true
if successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_stdoutopts | ( | sir_options | opts | ) |
Set new formatting options for stdout
.
By default, stdout
has the following formatting options:
To modify level registrations for stdout
, use sir_stdoutlevels.
opts | New bitmask of sir_option for stdout . If you wish to use the default values, pass SIRL_DEFAULT. |
true
if successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_syslogcat | ( | const char * | category | ) |
Set new system logger category.
Some system logger facilities (e.g. os_log
, the system logger on macOS), ask for a category string when logging messages-to more easily group messages together (which, as a byproduct, enhances searching).
If you are not utilizing a system logger that requires a category string, you do not need to call this function (or set sirinit.d_syslog.category).
Upon library initialization, the system logger category is resolved as follows:
SIR_NO_SYSTEM_LOGGERS
is defined when compiling libsir, this function will immediately return false, and set the last error to SIR_E_UNAVAIL.category | The string to use as the system logger category. |
true
if successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_syslogid | ( | const char * | identity | ) |
Set new system logger identity.
In the context of the system logger (i.e., syslog
/os_log
/etc.), identity refers to the name
that appears in the log for the current process.
Upon library initialization, the system logger identity is resolved as follows:
SIR_NO_SYSTEM_LOGGERS
is defined when compiling libsir, this function will immediately return false, and set the last error to SIR_E_UNAVAIL.identity | The string to use as the system logger identity. |
true
if successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_sysloglevels | ( | sir_levels | levels | ) |
Set new level registrations for the system logger destination.
By default, the system logger is registered for the following levels:
To modify formatting options for the system logger, use sir_syslogopts.
levels | New bitmask of sir_level to register for. If you wish to use the default levels, pass SIRL_DEFAULT. |
true
if successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_syslogopts | ( | sir_options | opts | ) |
Set new formatting options for the system logger destination.
By default, the system logger has the following formatting options:
To modify level registrations for the system logger, use sir_sysloglevels.
opts | New bitmask of sir_option for the system logger. If you wish to use the default values, pass SIRO_DEFAULT. |
true
if successfully updated, false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_unloadplugin | ( | sirpluginid | id | ) |
Unloads a previously registered plugin module.
Cleans up, de-registers, and unloads a plugin represented by id
(the value returned from sir_loadplugin).
If the plugin is located in the cache, it is instructed to clean up and prepare to be unloaded. Upon completion of the plugin's clean up routine, it is unloaded.
id | The sirpluginid obtained when the plugin was loaded. |
true
if the plugin was located and successfully unloaded,false
otherwise. Use sir_geterror to obtain information about any error that may have occurred. bool sir_warn | ( | PRINTF_FORMAT const char * | format, |
... ) |
Dispatches a SIRL_WARN level message.
The message will be delivered to all destinations registered to receive warning-level messages, each with their own formatting and styling options.
stdout
/stderr
, call sir_stdoutopts/sir_stdoutlevels and sir_stderropts/sir_stderrlevels, respectively. To change the text styling on a per-level basis, call sir_settextstyle.format | A printf-style format string, representing the template for the message to dispatch. |
... | Arguments whose type and position align with the format specifiers in format . |
true
if the message was dispatched successfully to all registered destinations, false
otherwise. Call sir_geterror to obtain information about any error that may have occurred.