diff --git a/examples/CC3200/bm222.c b/examples/CC3200/bm222.c index e62dc8e3..416c410f 100644 --- a/examples/CC3200/bm222.c +++ b/examples/CC3200/bm222.c @@ -6,6 +6,7 @@ #include "bm222.h" #include "mongoose.h" +#include "cs_dbg.h" #include "i2c_if.h" diff --git a/examples/CC3200/cs_dbg.h b/examples/CC3200/cs_dbg.h new file mode 120000 index 00000000..4c6bc66b --- /dev/null +++ b/examples/CC3200/cs_dbg.h @@ -0,0 +1 @@ +./../../../common/cs_dbg.h \ No newline at end of file diff --git a/examples/CC3200/data.c b/examples/CC3200/data.c index 7ad3e353..8365d21f 100644 --- a/examples/CC3200/data.c +++ b/examples/CC3200/data.c @@ -12,6 +12,7 @@ #include "bm222.h" #include "tmp006.h" +#include "cs_dbg.h" struct temp_data { double ts; diff --git a/examples/CC3200/main.c b/examples/CC3200/main.c index ec357324..676e0703 100644 --- a/examples/CC3200/main.c +++ b/examples/CC3200/main.c @@ -26,7 +26,7 @@ /* Mongoose.h brings in SimpleLink support. Do not include simplelink.h. */ #include - +#include "cs_dbg.h" #include #include "data.h" diff --git a/examples/CC3200/wifi.c b/examples/CC3200/wifi.c index 4929ffc2..035772f6 100644 --- a/examples/CC3200/wifi.c +++ b/examples/CC3200/wifi.c @@ -11,6 +11,7 @@ #include #include +#include "cs_dbg.h" void SimpleLinkWlanEventHandler(SlWlanEvent_t *e) { switch (e->Event) { diff --git a/examples/ESP8266_RTOS/user/cs_dbg.h b/examples/ESP8266_RTOS/user/cs_dbg.h new file mode 120000 index 00000000..a2154b8a --- /dev/null +++ b/examples/ESP8266_RTOS/user/cs_dbg.h @@ -0,0 +1 @@ +./../../../../common/cs_dbg.h \ No newline at end of file diff --git a/examples/ESP8266_RTOS/user/user_main.c b/examples/ESP8266_RTOS/user/user_main.c index c6587ff3..cbda034d 100644 --- a/examples/ESP8266_RTOS/user/user_main.c +++ b/examples/ESP8266_RTOS/user/user_main.c @@ -6,6 +6,7 @@ #include "esp_common.h" #include "mongoose.h" +#include "cs_dbg.h" #define AP_SSID "Mongoose" #define AP_PASS "Mongoose" diff --git a/examples/captive_dns_server/captive_dns_server.c b/examples/captive_dns_server/captive_dns_server.c index 0f170435..2005e14f 100644 --- a/examples/captive_dns_server/captive_dns_server.c +++ b/examples/captive_dns_server/captive_dns_server.c @@ -33,7 +33,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { char rname[256]; rr = &msg->questions[i]; mg_dns_uncompress_name(msg, &rr->name, rname, sizeof(rname) - 1); - LOG(LL_INFO, ("Q type %d name %s", rr->rtype, rname)); + fprintf(stdout, "Q type %d name %s\n", rr->rtype, rname); if (rr->rtype == MG_DNS_A_RECORD) { mg_dns_reply_record(&reply, rr, NULL, rr->rtype, 10, &s_our_ip_addr, 4); @@ -62,7 +62,6 @@ int main(int argc, char *argv[]) { mg_mgr_init(&mgr, NULL); s_our_ip_addr = inet_addr("127.0.0.1"); - cs_log_set_level(LL_INFO); /* Parse command line arguments */ for (i = 1; i < argc; i++) { diff --git a/mongoose.c b/mongoose.c index d31859cf..29bd8c86 100644 --- a/mongoose.c +++ b/mongoose.c @@ -55,6 +55,7 @@ /* Amalgamated: #include "mongoose/src/net.h" */ /* Amalgamated: #include "mongoose/src/http.h" */ +/* Amalgamated: #include "common/cs_dbg.h" */ #define MG_CTL_MSG_MESSAGE_SIZE 8192 @@ -120,6 +121,142 @@ extern void *(*test_calloc)(size_t count, size_t size); #endif /* CS_MONGOOSE_SRC_INTERNAL_H_ */ #ifdef MG_MODULE_LINES +#line 1 "./src/../../common/cs_dbg.h" +#endif +/* + * Copyright (c) 2014-2016 Cesanta Software Limited + * All rights reserved + */ + +#ifndef CS_COMMON_CS_DBG_H_ +#define CS_COMMON_CS_DBG_H_ + +#ifndef CS_DISABLE_STDIO +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +enum cs_log_level { + LL_NONE = -1, + LL_ERROR = 0, + LL_WARN = 1, + LL_INFO = 2, + LL_DEBUG = 3, + LL_VERBOSE_DEBUG = 4, + + _LL_MIN = -2, + _LL_MAX = 5, +}; + +void cs_log_set_level(enum cs_log_level level); + +#ifndef CS_DISABLE_STDIO + +void cs_log_set_file(FILE *file); + +extern enum cs_log_level cs_log_level; +void cs_log_print_prefix(const char *func); +void cs_log_printf(const char *fmt, ...); + +#define LOG(l, x) \ + if (cs_log_level >= l) { \ + cs_log_print_prefix(__func__); \ + cs_log_printf x; \ + } + +#ifndef CS_NDEBUG + +#define DBG(x) \ + if (cs_log_level >= LL_VERBOSE_DEBUG) { \ + cs_log_print_prefix(__func__); \ + cs_log_printf x; \ + } + +#else /* NDEBUG */ + +#define DBG(x) + +#endif + +#else /* CS_DISABLE_STDIO */ + +#define LOG(l, x) +#define DBG(x) + +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CS_COMMON_CS_DBG_H_ */ +#ifdef MG_MODULE_LINES +#line 1 "./src/../../common/cs_dbg.c" +#endif +/* + * Copyright (c) 2014-2016 Cesanta Software Limited + * All rights reserved + */ + +/* Amalgamated: #include "common/cs_dbg.h" */ + +#include +#include + +/* Amalgamated: #include "common/cs_time.h" */ + +enum cs_log_level cs_log_level = +#ifdef CS_ENABLE_DEBUG + LL_VERBOSE_DEBUG; +#else + LL_ERROR; +#endif + +#ifndef CS_DISABLE_STDIO + +FILE *cs_log_file = NULL; + +#ifdef CS_LOG_TS_DIFF +double cs_log_ts; +#endif + +void cs_log_print_prefix(const char *func) { + if (cs_log_file == NULL) cs_log_file = stderr; + fprintf(cs_log_file, "%-20s ", func); +#ifdef CS_LOG_TS_DIFF + { + double now = cs_time(); + fprintf(cs_log_file, "%7u ", (unsigned int) ((now - cs_log_ts) * 1000000)); + cs_log_ts = now; + } +#endif +} + +void cs_log_printf(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vfprintf(cs_log_file, fmt, ap); + va_end(ap); + fputc('\n', cs_log_file); + fflush(cs_log_file); +} + +void cs_log_set_file(FILE *file) { + cs_log_file = file; +} + +#endif /* !CS_DISABLE_STDIO */ + +void cs_log_set_level(enum cs_log_level level) { + cs_log_level = level; +#if defined(CS_LOG_TS_DIFF) && !defined(CS_DISABLE_STDIO) + cs_log_ts = cs_time(); +#endif +} +#ifdef MG_MODULE_LINES #line 1 "./src/../../common/base64.c" #endif /* @@ -323,69 +460,6 @@ int cs_base64_decode(const unsigned char *s, int len, char *dst) { #endif /* EXCLUDE_COMMON */ #ifdef MG_MODULE_LINES -#line 1 "./src/../../common/cs_dbg.c" -#endif -/* - * Copyright (c) 2014-2016 Cesanta Software Limited - * All rights reserved - */ - -/* Amalgamated: #include "common/cs_dbg.h" */ - -#include -#include - -/* Amalgamated: #include "common/cs_time.h" */ - -enum cs_log_level cs_log_level = -#ifdef CS_ENABLE_DEBUG - LL_VERBOSE_DEBUG; -#else - LL_ERROR; -#endif - -#ifndef CS_DISABLE_STDIO - -FILE *cs_log_file = NULL; - -#ifdef CS_LOG_TS_DIFF -double cs_log_ts; -#endif - -void cs_log_print_prefix(const char *func) { - if (cs_log_file == NULL) cs_log_file = stderr; - fprintf(cs_log_file, "%-20s ", func); -#ifdef CS_LOG_TS_DIFF - { - double now = cs_time(); - fprintf(cs_log_file, "%7u ", (unsigned int) ((now - cs_log_ts) * 1000000)); - cs_log_ts = now; - } -#endif -} - -void cs_log_printf(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - vfprintf(cs_log_file, fmt, ap); - va_end(ap); - fputc('\n', cs_log_file); - fflush(cs_log_file); -} - -void cs_log_set_file(FILE *file) { - cs_log_file = file; -} - -#endif /* !CS_DISABLE_STDIO */ - -void cs_log_set_level(enum cs_log_level level) { - cs_log_level = level; -#if defined(CS_LOG_TS_DIFF) && !defined(CS_DISABLE_STDIO) - cs_log_ts = cs_time(); -#endif -} -#ifdef MG_MODULE_LINES #line 1 "./src/../../common/cs_dirent.h" #endif /* diff --git a/mongoose.h b/mongoose.h index 6c3b0246..27ef6fe6 100644 --- a/mongoose.h +++ b/mongoose.h @@ -750,76 +750,6 @@ int sl_set_ssl_opts(struct mg_connection *nc); * All rights reserved */ -#ifndef CS_COMMON_CS_DBG_H_ -#define CS_COMMON_CS_DBG_H_ - -#ifndef CS_DISABLE_STDIO -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -enum cs_log_level { - LL_NONE = -1, - LL_ERROR = 0, - LL_WARN = 1, - LL_INFO = 2, - LL_DEBUG = 3, - LL_VERBOSE_DEBUG = 4, - - _LL_MIN = -2, - _LL_MAX = 5, -}; - -void cs_log_set_level(enum cs_log_level level); - -#ifndef CS_DISABLE_STDIO - -void cs_log_set_file(FILE *file); - -extern enum cs_log_level cs_log_level; -void cs_log_print_prefix(const char *func); -void cs_log_printf(const char *fmt, ...); - -#define LOG(l, x) \ - if (cs_log_level >= l) { \ - cs_log_print_prefix(__func__); \ - cs_log_printf x; \ - } - -#ifndef CS_NDEBUG - -#define DBG(x) \ - if (cs_log_level >= LL_VERBOSE_DEBUG) { \ - cs_log_print_prefix(__func__); \ - cs_log_printf x; \ - } - -#else /* NDEBUG */ - -#define DBG(x) - -#endif - -#else /* CS_DISABLE_STDIO */ - -#define LOG(l, x) -#define DBG(x) - -#endif - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CS_COMMON_CS_DBG_H_ */ -/* - * Copyright (c) 2014-2016 Cesanta Software Limited - * All rights reserved - */ - #ifndef CS_COMMON_CS_TIME_H_ #define CS_COMMON_CS_TIME_H_