It is possible to change how and where libexplain sends its output, and even how it calls the exit(2)
function. This functionality is used by the explain_*_or_die and explain_*_on_error functions.
By default, libexplain will wrap and print error messages on stderr, and call the exit(2) system call to
terminate execution.
Clients of the libexplain library may choose to use some message handling facilities provided by
libexplain, or they may choose to implement their own.
syslog
To cause all output to be sent to syslog, use
explain_output_register(explain_output_syslog_new());
This is useful for servers and daemons.
stderrandsyslog
The “tee” output class can be used to duplicate output. To cause all output to be sent to both
stderr and syslog, use
explain_output_register
(
explain_output_tee_new
(
explain_output_stderr_new(),
explain_output_syslog_new()
)
);
If you need more than two, use several instances of “tee”, cascaded.
stderrandafile
To cause all output to be sent to both stderr and a regular file, use
explain_output_register
(
explain_output_tee_new
(
explain_output_stderr_new(),
explain_output_file_new(filename, 0)
)
);
See the <libexplain/output.h> file for extensive documentation.
explain_output_new
explain_output_t *explain_output_new(const explain_output_vtable_t *vtable);
The explain_output_new function may be used to create a new dynamically allocated instance of
explain_output_t.
vtable The struct containing the pointers to the methods of the derived class.
returns NULL on error (i.e. malloc failed), or a pointer to a new dynamically allocated instance of the
class.
explain_output_stderr_new
explain_output_t *explain_output_stderr_new(void);
The explain_output_stderr_new function may be used to create a new dynamically allocated instance of an
explain_output_t class that writes to stderr, and exits via exit(2);
This is the default output handler.
returns NULL on error (i.e. malloc failed), or a pointer to a new dynamically allocated instance of the
stderr class.
explain_output_syslog_new
explain_output_t *explain_output_syslog_new(void);
The explain_output_syslog_new function may be used to create a new dynamically allocated instance of an
explain_output_t class that writes to syslog, and exits via exit(2);
The following values are used:
option = 0
facility = LOG_USER
level = LOG_ERR
See syslog(3) for more information.
returns NULL on error (i.e. malloc(3) failed), or a pointer to a new dynamically allocated instance of
the syslog class.
explain_output_syslog_new1
explain_output_t *explain_output_syslog_new1(int level);
The explain_output_syslog_new1 function may be used to create a new dynamically allocated instance of an
explain_output_t class that writes to syslog, and exits via exit(2);
The following values are used:
option = 0
facility = LOG_USER
See syslog(3) for more information.
level The syslog level to be used, see syslog(3) for a definition.
returns NULL on error (i.e. malloc(3) failed), or a pointer to a new dynamically allocated instance of
the syslog class.
explain_output_syslog_new3
explain_output_t *explain_output_syslog_new3(int option, int facility, int level);
The explain_output_syslog_new3 function may be used to create a new dynamically allocated instance of an
explain_output_t class that writes to syslog, and exits via exit(2);
If you want different facilities or levels, create multiple instances.
option The syslog option to be used, see syslog(3) for a definition.
facility
The syslog facility to be used, see syslog(3) for a definition.
level The syslog level to be used, see syslog(3) for a definition.
returns NULL on error (i.e. malloc(3) failed), or a pointer to a new dynamically allocated instance of
the syslog class.
explain_output_file_new
explain_output_t *explain_output_file_new(const char *filename, int append);
The explain_output_file_new function may be used to create a new dynamically allocated instance of an
explain_output_t class that writes to a file, and exits via exit(2).
filename
The file to be opened and written to.
append true (non‐zero) if messages are to be appended to the file, false (zero) if the file is to be
replaced with new contents.
returns NULL on error (i.e. malloc(3) or open(2) failed), or a pointer to a new dynamically allocated
instance of the syslog class.
explain_output_tee_new
explain_output_t *explain_output_tee_new(explain_output_t *first, explain_output_t *second);
The explain_output_tee_new function may be used to create a new dynamically allocated instance of an
explain_output_t class that writes to two other output classes.
first The first output class to write to.
second The second output class to write to.
returns NULL on error (i.e. malloc(3) failed), or a pointer to a new dynamically allocated instance of
the syslog class.
The output subsystem will “own” the first and second objects after this call. You may not make any
reference to these pointers ever again. The output subsystem will destroy these objects and free the
memory when it feels like it.
explain_output_register
void explain_output_register(explain_output_t *op);
The explain_output_register function is used to change libexplain's default output handling facilities
with something else. The NULL pointer restores libexplain's default processing.
If no output class is registered, the default is to wrap and print to stderr, and to exit via the exit(2)
system call.
op Pointer to the explain_output_t instance to be operated on.
The output subsystem will “own” the pointer after this call. You may not make any reference to this
pointer ever again. The output subsystem will destroy the object and free the memory when it feels like
it.