API: Logger messages stack

Overview

In order to use logger_stack you need to include te_log_stack.h

Usage examples:

// global functions

void te_log_stack_init_here(const char* top);
void te_log_stack_push_under(const char* user, const char* fmt, ...);
char* te_log_stack_pop(void);
void te_log_stack_dump(te_log_level log_level);
void te_log_stack_maybe_reset(const char* here);

// macros

#define te_log_stack_init()
#define te_log_stack_push(_fs...)
#define te_log_stack_reset()

Detailed Documentation

In order to use logger_stack you need to include te_log_stack.h

Usage examples:

#define TE_LGR_USER  "My module"

#include "te_config.h"
...
#include "te_log_stack.h"
...
int main()
{
    te_log_stack_init();

    ...
    te_log_stack_push(TE_LGR_USER, "An error condition happens: %s", result_string);
    CHECK_RC(FUNCTION_THAT_WILL_DO_PUSH);

And then if failure was unexpected you can call:

te_log_stack_dump(TE_LL_ERROR);

that will log full stack of errors and include them into your log file.

The stack is per-thread and is not allocated/initialized unless you call te_log_msg_stack_init() in the corresponding thread.

One limitation is that you can’t use ‘r’ specifier.

Global Functions

void te_log_stack_init_here(const char* top)

Initialize msg stack logic in the thread and set “top” point, i.e. location that code-wise is the source of all calls. te_log_stack_maybe_reset() calls will do nothing unless point at which we’re calling things is the top one.

Parameters:

top

String identifier of the top point. See ‘reset’ handling.

void te_log_stack_push_under(const char* user, const char* fmt, ...)

Push a message under specified user

Parameters:

user

Log user to be used, if NULL - internal one will be used

fmt

Format string ! r is not supported

char* te_log_stack_pop(void)

Pop message from the stack. Note, that you should free() the result once done working with it.

void te_log_stack_dump(te_log_level log_level)

Dump stack under given log level.

Parameters:

log_level

Log level (TE_LL_ERROR etc.)

void te_log_stack_maybe_reset(const char* here)

Reset/empty stack w/o logging things. Does not release any resources.

Parameters:

here

Name of the point we’re resetting things from. Normally it’s a file/function.

Macros

#define te_log_stack_push(_fs...)

Wrapper to used pre-defined TE_LGR_USER