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:
Deomid Ryabkov 2016-03-30 13:30:39 +01:00 committed by rojer
parent c9fc7a1320
commit fb53cd37e7
3 changed files with 32 additions and 20 deletions

View File

@ -366,6 +366,7 @@ int main() {
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
cs_log_set_file(stdout);
cs_log_set_level(LL_INFO);
MAP_PinTypeI2C(PIN_01, PIN_MODE_1); /* SDA */

View File

@ -346,41 +346,52 @@ int cs_base64_decode(const unsigned char *s, int len, char *dst) {
/* 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
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
#ifndef CS_DISABLE_STDIO
void cs_log_printf(const char *fmt, ...) {
va_list ap;
#ifdef CS_LOG_TS_DIFF
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
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
vfprintf(cs_log_file, fmt, ap);
va_end(ap);
fputc('\n', stderr);
fputc('\n', cs_log_file);
#ifdef CS_LOG_TS_DIFF
cs_log_ts = now;
#endif
fflush(stderr);
fflush(cs_log_file);
}
#endif /* !CS_DISABLE_STDIO */
void cs_log_set_level(enum cs_log_level level) {
s_cs_log_level = level;
#ifdef CS_LOG_TS_DIFF
cs_log_level = level;
#if defined(CS_LOG_TS_DIFF) && !defined(CS_DISABLE_STDIO)
cs_log_ts = cs_time();
#endif
}
void cs_log_set_file(FILE *file) {
cs_log_file = file;
}
#ifdef MG_MODULE_LINES
#line 1 "./src/../../common/cs_dirent.c"
#endif

View File

@ -637,29 +637,29 @@ enum cs_log_level {
_LL_MAX = 5,
};
extern enum cs_log_level s_cs_log_level;
void cs_log_set_level(enum cs_log_level level);
#ifndef CS_DISABLE_STDIO
#ifdef CS_LOG_TS_DIFF
extern double cs_log_ts;
#endif
#include <stdio.h>
void cs_log_set_file(FILE *file);
extern enum cs_log_level cs_log_level;
void cs_log_printf(const char *fmt, ...);
#define LOG(l, x) \
if (s_cs_log_level >= l) { \
fprintf(stderr, "%-20s ", __func__); \
cs_log_printf x; \
#define LOG(l, x) \
if (cs_log_level >= l) { \
cs_log_printf("%-20s ", __func__); \
cs_log_printf x; \
}
#ifndef CS_NDEBUG
#define DBG(x) \
if (s_cs_log_level >= LL_VERBOSE_DEBUG) { \
fprintf(stderr, "%-20s ", __func__); \
cs_log_printf x; \
#define DBG(x) \
if (cs_log_level >= LL_VERBOSE_DEBUG) { \
cs_log_printf("%-20s ", __func__); \
cs_log_printf x; \
}
#else /* NDEBUG */