feat(lnm): add logging framework
This commit is contained in:
parent
e44b7d0e5f
commit
3aa0ace863
4 changed files with 171 additions and 6 deletions
47
lnm/include/lnm/log.h
Normal file
47
lnm/include/lnm/log.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#ifndef LNM_LOG
|
||||
#define LOG
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "lnm/common.h"
|
||||
|
||||
typedef struct lnm_logger lnm_logger;
|
||||
|
||||
typedef enum lnm_log_level {
|
||||
lnm_log_level_debug = 0,
|
||||
lnm_log_level_info,
|
||||
lnm_log_level_notice,
|
||||
lnm_log_level_warning,
|
||||
lnm_log_level_error,
|
||||
lnm_log_level_critical
|
||||
} lnm_log_level;
|
||||
|
||||
extern const char *lnm_log_level_names[];
|
||||
|
||||
/**
|
||||
* Initialize the global logger.
|
||||
*/
|
||||
lnm_err lnm_log_init_global();
|
||||
|
||||
/**
|
||||
* Register stdout as one of the streams for the global logger.
|
||||
*/
|
||||
lnm_err lnm_log_register_stdout(lnm_log_level level);
|
||||
|
||||
void lnm_log(lnm_log_level level, const char *section, const char *fmt, ...)
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
|
||||
#define lnm_ldebug(section, fmt, ...) \
|
||||
lnm_log(lnm_log_level_debug, section, fmt, __VA_ARGS__)
|
||||
#define lnm_linfo(section, fmt, ...) \
|
||||
lnm_log(lnm_log_level_info, section, fmt, __VA_ARGS__)
|
||||
#define lnm_lnotice(section, fmt, ...) \
|
||||
lnm_log(lnm_log_level_notice, section, fmt, __VA_ARGS__)
|
||||
#define lnm_lwarning(section, fmt, ...) \
|
||||
lnm_log(lnm_log_level_warning, section, fmt, __VA_ARGS__)
|
||||
#define lnm_lerror(section, fmt, ...) \
|
||||
lnm_log(lnm_log_level_error, section, fmt, __VA_ARGS__)
|
||||
#define lnm_lcritical(section, fmt, ...) \
|
||||
lnm_log(lnm_log_level_critical, section, fmt, __VA_ARGS__)
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue