mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-05 22:08:23 +00:00
Move printing log prefix into a separate function
Reduces code size a bit and makes it cleaner PUBLISHED_FROM=c08064102dc64f59dcdc1f80655f32e1ed94c850
This commit is contained in:
1 parent
fb53cd37e7
commit
482ab33c03
2 files changed
+18
-16
No files matched your search
+12
-11
@@ -361,23 +361,24 @@ FILE *cs_log_file = NULL;
|
|||||||
double cs_log_ts;
|
double cs_log_ts;
|
||||||
#endif
|
#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, ...) {
|
void cs_log_printf(const char *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
#ifdef CS_LOG_TS_DIFF
|
|
||||||
double now = cs_time();
|
|
||||||
#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);
|
va_start(ap, fmt);
|
||||||
vfprintf(cs_log_file, fmt, ap);
|
vfprintf(cs_log_file, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
fputc('\n', cs_log_file);
|
fputc('\n', cs_log_file);
|
||||||
#ifdef CS_LOG_TS_DIFF
|
|
||||||
cs_log_ts = now;
|
|
||||||
#endif
|
|
||||||
fflush(cs_log_file);
|
fflush(cs_log_file);
|
||||||
}
|
}
|
||||||
#endif /* !CS_DISABLE_STDIO */
|
#endif /* !CS_DISABLE_STDIO */
|
||||||
|
|||||||
+6
-5
@@ -646,19 +646,20 @@ void cs_log_set_level(enum cs_log_level level);
|
|||||||
void cs_log_set_file(FILE *file);
|
void cs_log_set_file(FILE *file);
|
||||||
|
|
||||||
extern enum cs_log_level cs_log_level;
|
extern enum cs_log_level cs_log_level;
|
||||||
|
void cs_log_print_prefix(const char *func);
|
||||||
void cs_log_printf(const char *fmt, ...);
|
void cs_log_printf(const char *fmt, ...);
|
||||||
|
|
||||||
#define LOG(l, x) \
|
#define LOG(l, x) \
|
||||||
if (cs_log_level >= l) { \
|
if (cs_log_level >= l) { \
|
||||||
cs_log_printf("%-20s ", __func__); \
|
cs_log_print_prefix(__func__); \
|
||||||
cs_log_printf x; \
|
cs_log_printf x; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CS_NDEBUG
|
#ifndef CS_NDEBUG
|
||||||
|
|
||||||
#define DBG(x) \
|
#define DBG(x) \
|
||||||
if (cs_log_level >= LL_VERBOSE_DEBUG) { \
|
if (cs_log_level >= LL_VERBOSE_DEBUG) { \
|
||||||
cs_log_printf("%-20s ", __func__); \
|
cs_log_print_prefix(__func__); \
|
||||||
cs_log_printf x; \
|
cs_log_printf x; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user