CNDP
22.08.0
|
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <cne_common.h>
#include <cne_stdio.h>
#include "cne_build_config.h"
Go to the source code of this file.
Macros | |
#define | CNE_LOG(f, ...) cne_log(CNE_LOG_##f, __func__, __LINE__, #f ": " __VA_ARGS__) |
#define | CNE_PRINT(f, args...) cne_print(f, ##args) |
#define | CNE_EMERG(...) CNE_LOG(EMERG, __VA_ARGS__) |
#define | CNE_ERR_RET_VAL(_val, ...) |
#define | CNE_RET(...) CNE_ERR_RET_VAL(, __VA_ARGS__) |
#define | CNE_ERR_RET(...) CNE_ERR_RET_VAL(-1, __VA_ARGS__) |
#define | CNE_NULL_RET(...) CNE_ERR_RET_VAL(NULL, __VA_ARGS__) |
#define | CNE_ERR_GOTO(lbl, ...) |
#define | cne_panic(format, args...) __cne_panic(__func__, __LINE__, format "\n", ##args) |
#define | cne_exit(format, args...) __cne_exit(__func__, __LINE__, format "\n", ##args) |
#define | CNE_VERIFY(exp) |
Functions | |
CNDP_API void | cne_log_set_level (uint32_t level) |
CNDP_API int | cne_log_set_level_str (char *log_level) |
CNDP_API uint32_t | cne_log_get_level (void) |
CNDP_API int | cne_log (uint32_t level, const char *func, int line, const char *format,...) |
CNDP_API int | cne_print (const char *format,...) |
CNDP_API int | cne_vlog (uint32_t level, const char *func, int line, const char *format, va_list ap) |
CNDP_API void | cne_dump_stack (void) |
CNDP_API void | __cne_panic (const char *funcname, int line, const char *format,...) |
CNDP_API void | __cne_exit (const char *func, int line, const char *format,...) |
#define CNE_LOG | ( | f, | |
... | |||
) | cne_log(CNE_LOG_##f, __func__, __LINE__, #f ": " __VA_ARGS__) |
Generates a log message.
The CNE_LOG() macro is a helper that prefixes the string with the log level, function name, line number, and calls cne_log().
f | Log level. A value between EMERG (1) and DEBUG (8). The short name is expanded by the macro, so it cannot be an integer value. |
... | The fmt string, as in printf(3), followed by the variable arguments required by the format. |
#define CNE_PRINT | ( | f, | |
args... | |||
) | cne_print(f, ##args) |
Generates a log message regardless of log level.
f | The fmt string, as in printf(3), followed by the variable arguments required by the format. |
args | Variable arguments depend on Application. |
#define CNE_EMERG | ( | ... | ) | CNE_LOG(EMERG, __VA_ARGS__) |
#define CNE_ERR_RET_VAL | ( | _val, | |
... | |||
) |
Generate an Error log message and return value
Same as CNE_LOG(ERR,...) define, but returns -1 to enable this style of coding. if (val == error) { CNE_ERR("Error: Failed\n"); return -1; } Returning _val to the calling function.
#define CNE_RET | ( | ... | ) | CNE_ERR_RET_VAL(, __VA_ARGS__) |
Generate an Error log message and return
Same as CNE_LOG(ERR,...) define, but returns to enable this style of coding. if (val == error) { CNE_ERR("Error: Failed\n"); return; } Returning to the calling function.
#define CNE_ERR_RET | ( | ... | ) | CNE_ERR_RET_VAL(-1, __VA_ARGS__) |
Generate an Error log message and return -1
Same as CNE_LOG(ERR,...) define, but returns -1 to enable this style of coding. if (val == error) { CNE_ERR("Error: Failed\n"); return -1; } Returning a -1 to the calling function.
#define CNE_NULL_RET | ( | ... | ) | CNE_ERR_RET_VAL(NULL, __VA_ARGS__) |
Generate an Error log message and return NULL
Same as CNE_LOG(ERR,...) define, but returns NULL to enable this style of coding. if (val == error) { CNE_ERR("Error: Failed\n"); return NULL; } Returning a NULL to the calling function.
#define CNE_ERR_GOTO | ( | lbl, | |
... | |||
) |
Generate a Error log message and goto label
Same as CNE_LOG(ERR,...) define, but goes to a label to enable this style of coding. if (error condition) { CNE_ERR("Error: Failed\n"); goto lbl; }
#define cne_panic | ( | format, | |
args... | |||
) | __cne_panic(__func__, __LINE__, format "\n", ##args) |
Provide notification of a critical non-recoverable error and terminate execution abnormally.
Display the format string and its expanded arguments (printf-like).
In a linux environment, this function dumps the stack and calls abort() resulting in a core dump if enabled.
The function never returns.
format | The format string, followed by the variable list of arguments. |
args | Variable arguments depend on Application. |
#define cne_exit | ( | format, | |
args... | |||
) | __cne_exit(__func__, __LINE__, format "\n", ##args) |
Provide notification of a critical non-recoverable error and terminate execution abnormally by calling exit(-1).
Display the format string and its expanded arguments (printf-like).
The function never returns.
format | The format string, followed by the variable list of arguments. |
args | Variable arguments depend on Application. |
#define CNE_VERIFY | ( | exp | ) |
Verify an expression is true
Calls cne_panic() when the expression is false.
exp | The expression to test |
CNDP_API void cne_log_set_level | ( | uint32_t | level | ) |
Set the log level for a given type.
level | The level to be set. |
CNDP_API int cne_log_set_level_str | ( | char * | log_level | ) |
Set the log level by string.
log_level | The level to be set. |
CNDP_API uint32_t cne_log_get_level | ( | void | ) |
CNDP_API int cne_log | ( | uint32_t | level, |
const char * | func, | ||
int | line, | ||
const char * | format, | ||
... | |||
) |
Generates a log message.
The message will be sent to stdout.
The level argument determines if the log should be displayed or not, depending on the global cne_loglevel variable.
The preferred alternative is the CNE_LOG() macro because it adds the level in the logged string and sets the function name and line number automatically.
level | Log level. A value between CNE_LOG_EMERG (1) and CNE_LOG_DEBUG (8). |
func | Function name. |
line | Line Number. |
format | The format string, as in printf(3), followed by the variable arguments required by the format. |
CNDP_API int cne_print | ( | const char * | format, |
... | |||
) |
Generates a log message regardless of log level.
The message will be sent to stdout.
format | The format string, as in printf(3), followed by the variable arguments required by the format. |
CNDP_API int cne_vlog | ( | uint32_t | level, |
const char * | func, | ||
int | line, | ||
const char * | format, | ||
va_list | ap | ||
) |
Generates a log message.
The message will be sent to stdout.
The level argument determines if the log should be displayed or not, depending on the global cne_loglevel variable.
The preferred alternative is the CNE_LOG() macro because it adds the level in the logged string and sets the function name and line number automatically.
level | Log level. A value between CNE_LOG_EMERG (1) and CNE_LOG_DEBUG (8). |
func | Function name. |
line | Line Number. |
format | The format string, as in printf(3), followed by the variable arguments required by the format. |
ap | The va_list of the variable arguments required by the format. |
CNDP_API void cne_dump_stack | ( | void | ) |
Dump the stack of the calling core to the console.
CNDP_API void __cne_panic | ( | const char * | funcname, |
int | line, | ||
const char * | format, | ||
... | |||
) |
Provide notification of a critical non-recoverable error and stop.
This function should not be called directly. Refer to cne_panic() macro documentation.
CNDP_API void __cne_exit | ( | const char * | func, |
int | line, | ||
const char * | format, | ||
... | |||
) |
Provide notification of a critical non-recoverable error and stop.
This function should not be called directly. Refer to cne_exit() macro documentation.