Skip to content

Commit

Permalink
Add MG_ENABLE_CUSTOM_LOG
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Oct 8, 2023
1 parent e357cb3 commit ea2ff01
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
Expand All @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions mongoose.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
Expand All @@ -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');
Expand Down

0 comments on commit ea2ff01

Please sign in to comment.