el_oset_custom_put¶
NAME¶
el_set_custom_put - enables user to implement own printing device
SYNOPSIS¶
#include <embedlog.h>
int el_set_custom_put(el_custom_put clbk, void *user);
int el_oset_custom_put(struct el *el, el_custom_put clbk, void *user);
typedef int (*el_custom_put)(const char *s, size_t slen, void *user);
DESCRIPTION¶
Sets function pointer for custom message print. Function will receive complete messsage (after processsing) to print, just as it would be printed to ie. stderr or another facility. Both binary and string data can be received this way.
s points to a data buffer, it can be null terminated string, or arbitrary binary data - depending on which functions has been called.
slen contains size of s buffer. If s is null terminated string, then slen contains length of string including null terminator character. For binary data, it contains size of binary buffer.
user pointer can be used to pass own logger object where data shall be sent. For example it may contain pointer to el struct, if you don't use global el struct.
Function cannot fail. If NULL is passed, custom function won't be called. It is still mandatory to enable custom printing with el_option(3) - EL_OUT.
EXAMPLES¶
int custom_logger(const char *s, size_t slen, void *user) {
FILE *f = user;
/* s will contain string "i/print log" */
fwrite(s, slen, 1, f);
return 0;
}
FILE *f = fopen(log_file, "w");
el_set_custom_put(custom_logger, f);
el_print(ELI, "print log");
RETURN VALUE¶
0 on succes, or -1 and set errno on failure.