mongoose/src/log.h

37 lines
1.2 KiB
C
Raw Normal View History

2020-12-05 11:26:32 +00:00
#pragma once
#include "arch.h"
#include "config.h"
2022-08-13 15:37:55 +01:00
#include "fmt.h"
2020-12-05 11:26:32 +00:00
enum { MG_LL_NONE, MG_LL_ERROR, MG_LL_INFO, MG_LL_DEBUG, MG_LL_VERBOSE };
2023-11-02 09:25:38 +00:00
extern int mg_log_level; // Current log level, one of MG_LL_*
2022-06-08 22:09:11 +01:00
void mg_log(const char *fmt, ...);
2023-11-02 09:25:38 +00:00
void mg_log_prefix(int ll, const char *file, int line, const char *fname);
// bool mg_log2(int ll, const char *file, int line, const char *fmt, ...);
void mg_hexdump(const void *buf, size_t len);
2022-08-13 15:37:55 +01:00
void mg_log_set_fn(mg_pfn_t fn, void *param);
2023-11-02 09:25:38 +00:00
#define mg_log_set(level_) mg_log_level = (level_)
2022-06-19 09:04:22 +01:00
#if MG_ENABLE_LOG
2023-11-02 09:25:38 +00:00
#define MG_LOG(level, args) \
do { \
if ((level) <= mg_log_level) { \
mg_log_prefix((level), __FILE__, __LINE__, __func__); \
mg_log args; \
} \
2020-12-05 11:26:32 +00:00
} while (0)
2022-06-19 09:04:22 +01:00
#else
#define MG_LOG(level, args) \
do { \
if (0) mg_log args; \
} while (0)
#endif
#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
#define MG_INFO(args) MG_LOG(MG_LL_INFO, args)
#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)