el_init(3)

bofc manual pages

el_init(3)



 

NAME

el_init - initializes library and el for printing.  

SYNOPSIS

#include <embedlog.h>

int el_init(void)
int el_oinit(struct el *el)
struct el * el_new(void)  

DESCRIPTION

There are two types of functions in embedlog. Functions that use global static structure inside library, these functions don't accept el argument with options.

Another type are functions that accept additional el argument. These functions are prefixed with el_o.

el_init(3) initializes static global option structure. This option structure is used by all functions that don't accept el object parameter. If you want to use only one instance of embedlog, this is the function you want to use.

el_oinit(3) initializes only el struct passed to it. Functions that accepts el object may be used. If you want to have multiple embedlog instances (ie. one for program logs, and one for queries) that stores logs differently - this is the function you want to use. Object initialized with this function must be deinitialized with el_ocleanup(3) function.

el_new(3) Works in the same way as el_oinit(3) but function returns newly heap-allocated pointer to el struct. Object created with this function must be destroyed with el_destroy(3) function.  

NOTES

Keep in mind that using el_oinit(3) function is suscible to ABI breakage. If stable ABI is important to you, use el_new(3) function. Please check el_overview(3) for more information about this.  

RETURN VALUE

el_init(3) cannot fail and always returns 0. el_oinit(3) function will return 0 upon success and -1 on errors. el_new(3) returns valid pointer on success and NULL when error occurs.  

ERRORS

el_oinit(3) can return:

EINVAL
el object is invalid (null).

el_new(3) can return:

ENOMEM
Not enough memory in the system to perform necessary memory allocations.
 

EXAMPLE

Note: error handling has been ommited for clarity sake

    #include <embedlog.h>

    int main(void)
    {
        struct el  el, *elp;

        /* initialize default and two custom el objects */
        el_init();
        el_oinit(&el);
        elp = el_new();

        /* make el to print to file and stderr */
        el_ooption(&el, EL_OUT, EL_OUT_FILE | EL_OUT_STDERR);
        el_ooption(&el, EL_FPATH, "/tmp/test.log");

        /* print messages */
        el_print(ELI, "will print to stderr");
        el_oprint(ELI, &el, "will print to file /tmp/test.log and stderr");
        el_oprint(ELN, elp, "print to stderr");

        /* cleanup after any initialization code (like fopen) */
        el_destroy(elp);
        el_ocleanup(&el);
        el_cleanup();

        return 0;
    }
 

SEE ALSO

el_overview(7), el_cleanup(3), el_destroy(3), el_flush(3), el_ocleanup(3), el_oflush(3), el_ooption(3), el_operror(3), el_opmemory(3), el_opmemory_table(3), el_oprint(3), el_option(3), el_oputs(3), el_ovprint(3), el_perror(3), el_pmemory(3), el_pmemory_table(3), el_print(3), el_puts(3), el_vprint(3).

bofc.pl

25 January 2021 (v0.6.0)

el_init(3)