void VLog(LogLevel level, const char *fmt, va_list ap) { LoggingContext *lctx = GetCurrentThreadContext(); char *msg = StringVFormat(fmt, ap); const char *hooked_msg = NULL; if (lctx->pctx && lctx->pctx->log_hook) { hooked_msg = lctx->pctx->log_hook(lctx->pctx, msg); } else { hooked_msg = msg; } if (level <= lctx->report_level) { LogToStdout(hooked_msg, level, lctx->color); } if (level <= lctx->log_level) { LogToSystemLog(hooked_msg, level); } free(msg); }
char *test_stringvformat_sup(const char *s, ...) { va_list ap; va_start(ap, s); char *fmted = StringVFormat(s, ap); va_end(ap); return fmted; }
char *StringFormat(const char *fmt, ...) { va_list ap; va_start(ap, fmt); char *res = StringVFormat(fmt, ap); va_end(ap); return res; }
void VLog(LogLevel level, const char *fmt, va_list ap) { LoggingContext *lctx = GetCurrentThreadContext(); bool log_to_console = ( level <= lctx->report_level ); bool log_to_syslog = ( level <= lctx->log_level && level < LOG_LEVEL_VERBOSE ); bool force_hook = ( lctx->pctx && lctx->pctx->log_hook && lctx->pctx->force_hook_level >= level ); if (!log_to_console && !log_to_syslog && !force_hook) { return; /* early return - save resources */ } char *msg = StringVFormat(fmt, ap); char *hooked_msg = NULL; /* Remove ending EOLN. */ for (char *sp = msg; *sp != '\0'; sp++) { if (*sp == '\n' && *(sp+1) == '\0') { *sp = '\0'; break; } } if (lctx->pctx && lctx->pctx->log_hook) { hooked_msg = lctx->pctx->log_hook(lctx->pctx, level, msg); } else { hooked_msg = msg; } if (log_to_console) { LogToConsole(hooked_msg, level, lctx->color); } if (log_to_syslog) { LogToSystemLog(hooked_msg, level); } if (hooked_msg != msg) { free(hooked_msg); } free(msg); }
void VLog(LogLevel level, const char *fmt, va_list ap) { LoggingContext *lctx = GetCurrentThreadContext(); char *msg = StringVFormat(fmt, ap); char *hooked_msg = NULL; for (char *sp = msg; *sp != '\0'; sp++) { if (*sp == '\n' && *(sp+1) == '\0') { *sp = '\0'; break; } } if (lctx->pctx && lctx->pctx->log_hook) { hooked_msg = lctx->pctx->log_hook(lctx->pctx, level, msg); } else { hooked_msg = xstrdup(msg); } if (level <= lctx->report_level) { if (MACHINE_OUTPUT) { LogToConsole(hooked_msg, level, lctx->color); } else { LogToConsole(msg, level, lctx->color); } } if (level <= lctx->log_level && level < LOG_LEVEL_VERBOSE) { LogToSystemLog(hooked_msg, level); } free(msg); free(hooked_msg); }