mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-28 05:39:00 +08:00
Make it possible to set log file
And use stdout for CC3200 demo because (1) an apparent bug which causes output sent to stderr to be printed v-e-r-y s-l-o-w-l-y (yes, it is really like that; https://e2e.ti.com/support/development_tools/code_composer_studio/f/81/t/501881) (2) in CCS it is printed in BLOOD RED, which is annoying PUBLISHED_FROM=36a86744bc8ea193e99e98670dadc7f3ab6ed53e
This commit is contained in:
parent
c9fc7a1320
commit
fb53cd37e7
@ -366,6 +366,7 @@ int main() {
|
|||||||
|
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
setvbuf(stderr, NULL, _IONBF, 0);
|
setvbuf(stderr, NULL, _IONBF, 0);
|
||||||
|
cs_log_set_file(stdout);
|
||||||
cs_log_set_level(LL_INFO);
|
cs_log_set_level(LL_INFO);
|
||||||
|
|
||||||
MAP_PinTypeI2C(PIN_01, PIN_MODE_1); /* SDA */
|
MAP_PinTypeI2C(PIN_01, PIN_MODE_1); /* SDA */
|
||||||
|
27
mongoose.c
27
mongoose.c
@ -346,41 +346,52 @@ int cs_base64_decode(const unsigned char *s, int len, char *dst) {
|
|||||||
|
|
||||||
/* Amalgamated: #include "common/cs_time.h" */
|
/* Amalgamated: #include "common/cs_time.h" */
|
||||||
|
|
||||||
enum cs_log_level s_cs_log_level =
|
enum cs_log_level cs_log_level =
|
||||||
#ifdef CS_ENABLE_DEBUG
|
#ifdef CS_ENABLE_DEBUG
|
||||||
LL_VERBOSE_DEBUG;
|
LL_VERBOSE_DEBUG;
|
||||||
#else
|
#else
|
||||||
LL_ERROR;
|
LL_ERROR;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef CS_DISABLE_STDIO
|
||||||
|
|
||||||
|
FILE *cs_log_file = NULL;
|
||||||
|
|
||||||
#ifdef CS_LOG_TS_DIFF
|
#ifdef CS_LOG_TS_DIFF
|
||||||
double cs_log_ts;
|
double cs_log_ts;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CS_DISABLE_STDIO
|
|
||||||
void cs_log_printf(const char *fmt, ...) {
|
void cs_log_printf(const char *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
#ifdef CS_LOG_TS_DIFF
|
#ifdef CS_LOG_TS_DIFF
|
||||||
double now = cs_time();
|
double now = cs_time();
|
||||||
fprintf(stderr, "%7u ", (unsigned int) ((now - cs_log_ts) * 1000000));
|
#endif
|
||||||
|
|
||||||
|
if (cs_log_file == NULL) cs_log_file = stderr;
|
||||||
|
#ifdef CS_LOG_TS_DIFF
|
||||||
|
fprintf(cs_log_file, "%7u ", (unsigned int) ((now - cs_log_ts) * 1000000));
|
||||||
#endif
|
#endif
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vfprintf(stderr, fmt, ap);
|
vfprintf(cs_log_file, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
fputc('\n', stderr);
|
fputc('\n', cs_log_file);
|
||||||
#ifdef CS_LOG_TS_DIFF
|
#ifdef CS_LOG_TS_DIFF
|
||||||
cs_log_ts = now;
|
cs_log_ts = now;
|
||||||
#endif
|
#endif
|
||||||
fflush(stderr);
|
fflush(cs_log_file);
|
||||||
}
|
}
|
||||||
#endif /* !CS_DISABLE_STDIO */
|
#endif /* !CS_DISABLE_STDIO */
|
||||||
|
|
||||||
void cs_log_set_level(enum cs_log_level level) {
|
void cs_log_set_level(enum cs_log_level level) {
|
||||||
s_cs_log_level = level;
|
cs_log_level = level;
|
||||||
#ifdef CS_LOG_TS_DIFF
|
#if defined(CS_LOG_TS_DIFF) && !defined(CS_DISABLE_STDIO)
|
||||||
cs_log_ts = cs_time();
|
cs_log_ts = cs_time();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cs_log_set_file(FILE *file) {
|
||||||
|
cs_log_file = file;
|
||||||
|
}
|
||||||
#ifdef MG_MODULE_LINES
|
#ifdef MG_MODULE_LINES
|
||||||
#line 1 "./src/../../common/cs_dirent.c"
|
#line 1 "./src/../../common/cs_dirent.c"
|
||||||
#endif
|
#endif
|
||||||
|
24
mongoose.h
24
mongoose.h
@ -637,29 +637,29 @@ enum cs_log_level {
|
|||||||
_LL_MAX = 5,
|
_LL_MAX = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern enum cs_log_level s_cs_log_level;
|
|
||||||
void cs_log_set_level(enum cs_log_level level);
|
void cs_log_set_level(enum cs_log_level level);
|
||||||
|
|
||||||
#ifndef CS_DISABLE_STDIO
|
#ifndef CS_DISABLE_STDIO
|
||||||
|
|
||||||
#ifdef CS_LOG_TS_DIFF
|
#include <stdio.h>
|
||||||
extern double cs_log_ts;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
void cs_log_set_file(FILE *file);
|
||||||
|
|
||||||
|
extern enum cs_log_level cs_log_level;
|
||||||
void cs_log_printf(const char *fmt, ...);
|
void cs_log_printf(const char *fmt, ...);
|
||||||
|
|
||||||
#define LOG(l, x) \
|
#define LOG(l, x) \
|
||||||
if (s_cs_log_level >= l) { \
|
if (cs_log_level >= l) { \
|
||||||
fprintf(stderr, "%-20s ", __func__); \
|
cs_log_printf("%-20s ", __func__); \
|
||||||
cs_log_printf x; \
|
cs_log_printf x; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CS_NDEBUG
|
#ifndef CS_NDEBUG
|
||||||
|
|
||||||
#define DBG(x) \
|
#define DBG(x) \
|
||||||
if (s_cs_log_level >= LL_VERBOSE_DEBUG) { \
|
if (cs_log_level >= LL_VERBOSE_DEBUG) { \
|
||||||
fprintf(stderr, "%-20s ", __func__); \
|
cs_log_printf("%-20s ", __func__); \
|
||||||
cs_log_printf x; \
|
cs_log_printf x; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* NDEBUG */
|
#else /* NDEBUG */
|
||||||
|
Loading…
Reference in New Issue
Block a user