From ea2ff010a9fbae2a1ffc2d41deda14cb7efa8f95 Mon Sep 17 00:00:00 2001 From: cpq Date: Sun, 8 Oct 2023 17:09:14 +0100 Subject: [PATCH] Add MG_ENABLE_CUSTOM_LOG --- mongoose.c | 4 ++++ mongoose.h | 4 ++++ src/config.h | 4 ++++ src/log.c | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/mongoose.c b/mongoose.c index a4f079a3..31e0cc4e 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3217,6 +3217,9 @@ void mg_log_set(int log_level) { s_level = log_level; } +#if MG_ENABLE_CUSTOM_LOG +// Let user define their own mg_log_prefix() and mg_log() +#else bool mg_log_prefix(int level, const char *file, int line, const char *fname) { if (level <= s_level) { const char *p = strrchr(file, '/'); @@ -3241,6 +3244,7 @@ void mg_log(const char *fmt, ...) { va_end(ap); logs("\r\n", 2); } +#endif static unsigned char nibble(unsigned c) { return (unsigned char) (c < 10 ? c + '0' : c + 'W'); diff --git a/mongoose.h b/mongoose.h index ff6a87d7..45f3dd91 100644 --- a/mongoose.h +++ b/mongoose.h @@ -669,6 +669,10 @@ struct timeval { #define MG_ENABLE_LOG 1 #endif +#ifndef MG_ENABLE_CUSTOM_LOG +#define MG_ENABLE_CUSTOM_LOG 0 // Let user define their own MG_LOG +#endif + #ifndef MG_ENABLE_TCPIP #define MG_ENABLE_TCPIP 0 // Mongoose built-in network stack #endif diff --git a/src/config.h b/src/config.h index f69da657..4d2db236 100644 --- a/src/config.h +++ b/src/config.h @@ -4,6 +4,10 @@ #define MG_ENABLE_LOG 1 #endif +#ifndef MG_ENABLE_CUSTOM_LOG +#define MG_ENABLE_CUSTOM_LOG 0 // Let user define their own MG_LOG +#endif + #ifndef MG_ENABLE_TCPIP #define MG_ENABLE_TCPIP 0 // Mongoose built-in network stack #endif diff --git a/src/log.c b/src/log.c index b3d16c04..02c6604c 100644 --- a/src/log.c +++ b/src/log.c @@ -26,6 +26,9 @@ void mg_log_set(int log_level) { s_level = log_level; } +#if MG_ENABLE_CUSTOM_LOG +// Let user define their own mg_log_prefix() and mg_log() +#else bool mg_log_prefix(int level, const char *file, int line, const char *fname) { if (level <= s_level) { const char *p = strrchr(file, '/'); @@ -50,6 +53,7 @@ void mg_log(const char *fmt, ...) { va_end(ap); logs("\r\n", 2); } +#endif static unsigned char nibble(unsigned c) { return (unsigned char) (c < 10 ? c + '0' : c + 'W');