Log buffers

Overview

Declaration of API to collect long log messages. More…

// typedefs

typedef struct te_log_buf_bit2str te_bit2str;
typedef struct te_log_buf_flag2str te_flag2str;
typedef struct te_log_buf te_log_buf;

// structs

struct te_log_buf_bit2str;
struct te_log_buf_flag2str;

// global functions

void te_log_bufs_cleanup(void);
te_string* te_log_str_alloc(void);
te_errno te_args2te_str(te_string* str, int argc, const char** argv);
te_errno te_bit_mask2te_str(te_string* str, unsigned long long bit_mask, const te_bit2str* map);
te_errno te_extended_bit_mask2te_str(te_string* str, unsigned long long bit_mask, const te_bit2str* bm, const te_flag2str* fm);
te_log_buf* te_log_buf_alloc(void);
int te_log_buf_append(te_log_buf* buf, const char* fmt, ...);
const char* te_log_buf_get(te_log_buf* buf);
void te_log_buf_free(te_log_buf* buf);
const char* te_args2log_buf(te_log_buf* buf, int argc, const char** argv);
const char* te_bit_mask2log_buf(te_log_buf* buf, unsigned long long bit_mask, const struct te_log_buf_bit2str* map);
const char* te_extended_bit_mask2log_buf(te_log_buf* buf, unsigned long long bit_mask, const struct te_log_buf_bit2str* bm, const struct te_log_buf_flag2str* fm);
const char* te_ether_addr2log_buf(te_log_buf* buf, const uint8_t* mac_addr);

Detailed Documentation

Declaration of API to collect long log messages.

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Typedefs

typedef struct te_log_buf_bit2str te_bit2str

Mapping of the bit number to string

typedef struct te_log_buf_flag2str te_flag2str

Mapping of the flag within mask to string

Global Functions

void te_log_bufs_cleanup(void)

Free all resources allocated for logging buffers. This function actually destroys all the existing buffers, not just marks them free for further use.

te_string* te_log_str_alloc(void)

Obtain reusable TE string for logging. The string can then be used like a normal TE string, however its buffer cannot be replaced by te_string_set_buf(). Obtained string must be released with te_string_free().

Returns:

TE string pointer or NULL on failure.

te_errno te_args2te_str(te_string* str, int argc, const char** argv)

Append argc/ argv arguments enclosed in double quotes and separated by comma to TE string.

Parameters:

str

Pointer to TE string

argc

Number of arguments

argv

Array with arguments

Returns:

Status code.

te_errno te_bit_mask2te_str(te_string* str, unsigned long long bit_mask, const te_bit2str* map)

Append bit mask converted to string to TE string.

Pipe ‘|’ is used as a separator.

Parameters:

str

Pointer to TE string

bit_mask

Bit mask

map

Bit to string map terminated by the element with NULL string

Returns:

Status code.

te_errno te_extended_bit_mask2te_str(te_string* str, unsigned long long bit_mask, const te_bit2str* bm, const te_flag2str* fm)

Extended version of te_bit_mask2te_str(). First it checks for all bits from bm, unsetting them in bit_mask. Then the bits which are left are checked against flags from fm.

Pipe ‘|’ is used as a separator.

Parameters:

str

Pointer to TE string

bit_mask

Bit mask

bm

Bit to string map terminated by the element with NULL string

fm

Flag within some mask to string map terminated by the element with NULL string

Returns:

Status code.

te_log_buf* te_log_buf_alloc(void)

Allocates a buffer to be used for accumulating log message. Mainly used in tapi_snmp itself.

This function is deprecated. Use te_log_str_alloc().

the caller does not have to check the returned value against NULL, the function blocks the caller until it gets available buffer.

This is thread safe function

Returns:

Pointer to the buffer.

int te_log_buf_append(te_log_buf* buf, const char* fmt, ...)

Appends format string to the log message, the behaviour of the function is the same as ordinary printf-like function.

This is NOT thread safe function, so you are not allowed to append the same buffer from different threads simultaneously.

Parameters:

buf

Pointer to the buffer allocated with te_log_buf_alloc()

fmt

Format string followed by parameters

Returns:

The number of characters appended

const char* te_log_buf_get(te_log_buf* buf)

Returns current log message accumulated in the buffer.

Parameters:

buf

Pointer to the buffer

Returns:

log message

void te_log_buf_free(te_log_buf* buf)

Release buffer allocated by te_log_buf_alloc()

This is thread safe function

Parameters:

buf

Pointer to the buffer

const char* te_args2log_buf(te_log_buf* buf, int argc, const char** argv)

Put argc/ argv arguments enclosed in double quotes and separated by comma to log buffer.

This function is deprecated. te_args2te_str() can be used with TE string instead.

Parameters:

buf

Pointer to the buffer allocated with te_log_buf_alloc()

argc

Number of arguments

argv

Array with arguments

Returns:

te_log_buf_get() return value after addition

const char* te_bit_mask2log_buf(te_log_buf* buf, unsigned long long bit_mask, const struct te_log_buf_bit2str* map)

Append bit mask converted to string to log buffer.

Pipe ‘|’ is used as a separator.

This function is deprecated. te_bit_mask2te_str() can be used with TE string instead.

Parameters:

buf

Pointer to the buffer

bit_mask

Bit mask

map

Bit to string map terminated by the element with NULL string

Returns:

te_log_buf_get() value.

const char* te_extended_bit_mask2log_buf(te_log_buf* buf, unsigned long long bit_mask, const struct te_log_buf_bit2str* bm, const struct te_log_buf_flag2str* fm)

Append extended bit mask converted to string to log buffer.

Pipe ‘|’ is used as a separator.

This function is deprecated. te_extended_bit_mask2te_str() can be used with TE string instead.

Parameters:

buf

Pointer to the buffer

bit_mask

Bit mask

bm

Bit to string map terminated by the element with NULL string

fm

Flag within some mask to string map terminated by the element with NULL string

Returns:

te_log_buf_get() value.

const char* te_ether_addr2log_buf(te_log_buf* buf, const uint8_t* mac_addr)

Put ether address to log buffer.

This function is deprecated. te_mac_addr2te_str() can be used with TE string instead.

Parameters:

buf

Pointer to the buffer allocated with te_log_buf_alloc()

mac_addr

Pointer to the ether address

Returns:

te_log_buf_get() return value after addition