lnm/include/lnm/log.h

48 lines
1.5 KiB
C

#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