Add mg_log_set_fn(), MG_ENABLE_LOG

This commit is contained in:
Sergey Lyubka committed 2022-06-19 09:04:22 +01:00
1 parent 0b5a00c99a
commit 9760b7c9d6
6 files changed
+69 -11

No files matched your search

+4 -4
View File
@@ -1,5 +1,9 @@
#pragma once
#ifndef MG_ENABLE_LOG
#define MG_ENABLE_LOG 1
#endif
#ifndef MG_ENABLE_MIP
#define MG_ENABLE_MIP 0
#endif
@@ -102,7 +106,3 @@
#define MG_ENABLE_FILE 0
#endif
#endif
#ifndef MG_PUTCHAR
#define MG_PUTCHAR(x) putchar(x)
#endif
+10 -1
View File
@@ -1,10 +1,19 @@
#include "log.h"
#include "util.h"
static void default_logger(unsigned char c) {
putchar(c);
}
static const char *s_spec = "2";
static void (*s_log_func)(unsigned char) = default_logger;
void mg_log_set_callback(void (*fn)(unsigned char)) {
s_log_func = fn;
}
static void logc(unsigned char c) {
MG_PUTCHAR(c);
s_log_func(c);
}
static void logs(const char *buf, size_t len) {
+8
View File
@@ -8,11 +8,19 @@ void mg_log(const char *fmt, ...);
bool mg_log_prefix(int ll, const char *file, int line, const char *fname);
void mg_log_set(const char *spec);
void mg_hexdump(const void *buf, size_t len);
void mg_log_set_fn(void (*logfunc)(unsigned char ch));
#if MG_ENABLE_LOG
#define MG_LOG(level, args) \
do { \
if (mg_log_prefix((level), __FILE__, __LINE__, __func__)) mg_log args; \
} while (0)
#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)