//lint -e{818} void vtc_log(struct vtclog *vl, int lvl, const char *fmt, ...) { double tx; CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC); tx = VTIM_mono() - t0; AZ(pthread_mutex_lock(&vl->mtx)); vl->act = 1; assert(lvl < (int)NLEAD); VSB_clear(vl->vsb); VSB_printf(vl->vsb, "%s %-4s %4.1f ", lead[lvl < 0 ? 1: lvl], vl->id, tx); va_list ap; va_start(ap, fmt); (void)VSB_vprintf(vl->vsb, fmt, ap); va_end(ap); VSB_putc(vl->vsb, '\n'); AZ(VSB_finish(vl->vsb)); vtc_log_emit(vl, lvl); VSB_clear(vl->vsb); vl->act = 0; AZ(pthread_mutex_unlock(&vl->mtx)); if (lvl > 0) return; if (lvl == 0) vtc_error = 1; if (pthread_self() != vtc_thread) pthread_exit(NULL); }
//lint -e{818} void vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...) { CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC); AZ(pthread_mutex_lock(&vl->mtx)); assert(lvl < NLEAD); vsb_clear(vl->vsb); vsb_printf(vl->vsb, "%s %-4s ", lead[lvl], vl->id); va_list ap; va_start(ap, fmt); (void)vsb_vprintf(vl->vsb, fmt, ap); va_end(ap); vsb_putc(vl->vsb, '\n'); vsb_finish(vl->vsb); AZ(vsb_overflowed(vl->vsb)); vtc_log_emit(vl, lvl); vsb_clear(vl->vsb); AZ(pthread_mutex_unlock(&vl->mtx)); if (lvl == 0) { vtc_error = 1; if (pthread_self() != vtc_thread) pthread_exit(NULL); } }
//lint -e{818} void vtc_hexdump(struct vtclog *vl, int lvl, const char *pfx, const unsigned char *str, int len) { int nl = 1; unsigned l; double tx; CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC); tx = VTIM_mono() - t0; assert(len >= 0); assert(lvl >= 0); assert(lvl < NLEAD); AZ(pthread_mutex_lock(&vl->mtx)); vl->act = 1; VSB_clear(vl->vsb); if (pfx == NULL) pfx = ""; if (str == NULL) VSB_printf(vl->vsb, "%s %-4s %4.1f %s| (null)", lead[lvl], vl->id, tx, pfx); else { for (l = 0; l < len; l++, str++) { if (l > 512) { VSB_printf(vl->vsb, "..."); break; } if (nl) { VSB_printf(vl->vsb, "%s %-4s %4.1f %s| ", lead[lvl], vl->id, tx, pfx); nl = 0; } VSB_printf(vl->vsb, " %02x", *str); if ((l & 0xf) == 0xf) { VSB_printf(vl->vsb, "\n"); nl = 1; } } } if (!nl) VSB_printf(vl->vsb, "\n"); AZ(VSB_finish(vl->vsb)); vtc_log_emit(vl, lvl); VSB_clear(vl->vsb); vl->act = 0; AZ(pthread_mutex_unlock(&vl->mtx)); if (lvl == 0) { vtc_error = 1; if (pthread_self() != vtc_thread) pthread_exit(NULL); } }
//lint -e{818} void vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str) { int nl = 1; CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC); assert(lvl < NLEAD); AZ(pthread_mutex_lock(&vl->mtx)); vsb_clear(vl->vsb); if (pfx == NULL) pfx = ""; if (str == NULL) vsb_printf(vl->vsb, "%s %-4s %s(null)\n", lead[lvl], vl->id, pfx); else for(; *str != '\0'; str++) { if (nl) { vsb_printf(vl->vsb, "%s %-4s %s| ", lead[lvl], vl->id, pfx); nl = 0; } if (*str == '\r') vsb_printf(vl->vsb, "\\r"); else if (*str == '\t') vsb_printf(vl->vsb, "\\t"); else if (*str == '\n') { vsb_printf(vl->vsb, "\\n\n"); nl = 1; } else if (*str < 0x20 || *str > 0x7e) vsb_printf(vl->vsb, "\\x%02x", *str); else vsb_printf(vl->vsb, "%c", *str); } if (!nl) vsb_printf(vl->vsb, "\n"); vsb_finish(vl->vsb); AZ(vsb_overflowed(vl->vsb)); vtc_log_emit(vl, lvl); vsb_clear(vl->vsb); AZ(pthread_mutex_unlock(&vl->mtx)); if (lvl == 0) { vtc_error = 1; if (pthread_self() != vtc_thread) pthread_exit(NULL); } }
//lint -e{818} void vtc_dump(struct vtclog *vl, int lvl, const char *pfx, const char *str, int len) { int nl = 1, olen; unsigned l; double tx; CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC); tx = VTIM_mono() - t0; assert(lvl >= 0); assert(lvl < NLEAD); AZ(pthread_mutex_lock(&vl->mtx)); vl->act = 1; VSB_clear(vl->vsb); if (pfx == NULL) pfx = ""; if (str == NULL) VSB_printf(vl->vsb, "%s %-4s %4.1f %s(null)\n", lead[lvl], vl->id, tx, pfx); else { olen = len; if (len < 0) len = strlen(str); for (l = 0; l < len; l++, str++) { if (l > 1024 && olen != -2) { VSB_printf(vl->vsb, "..."); break; } if (nl) { VSB_printf(vl->vsb, "%s %-4s %4.1f %s| ", lead[lvl], vl->id, tx, pfx); nl = 0; } if (*str == '\r') VSB_printf(vl->vsb, "\\r"); else if (*str == '\t') VSB_printf(vl->vsb, "\\t"); else if (*str == '\n') { VSB_printf(vl->vsb, "\\n\n"); nl = 1; } else if (*str < 0x20 || *str > 0x7e) VSB_printf(vl->vsb, "\\x%02x", (*str) & 0xff); else VSB_printf(vl->vsb, "%c", *str); } } if (!nl) VSB_printf(vl->vsb, "\n"); AZ(VSB_finish(vl->vsb)); vtc_log_emit(vl, lvl); VSB_clear(vl->vsb); vl->act = 0; AZ(pthread_mutex_unlock(&vl->mtx)); if (lvl == 0) { vtc_error = 1; if (pthread_self() != vtc_thread) pthread_exit(NULL); } }