/* Formatted output to print handler and/or logfile */ static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap) { char buf[256]; int len; if (level > dbg.level) return; if (!dbg.ph && !dbg.f) return; dbg_lock(); len = re_vsnprintf(buf, sizeof(buf), fmt, ap); if (len <= 0) goto out; /* Print handler? */ if (dbg.ph) { dbg.ph(level, buf, len, dbg.arg); } /* Output to file */ if (dbg.f) { if (fwrite(buf, 1, len, dbg.f) > 0) (void)fflush(dbg.f); } out: dbg_unlock(); }
/* NOTE: This function should not allocate memory */ static void dbg_vprintf(int level, const char *fmt, va_list ap) { if (level > dbg.level) return; /* Print handler? */ if (dbg.ph) return; dbg_lock(); if (dbg.flags & DBG_ANSI) { switch (level) { case DBG_WARNING: (void)re_fprintf(stderr, "\x1b[31m"); /* Red */ break; case DBG_NOTICE: (void)re_fprintf(stderr, "\x1b[33m"); /* Yellow */ break; case DBG_INFO: (void)re_fprintf(stderr, "\x1b[32m"); /* Green */ break; default: break; } } if (dbg.flags & DBG_TIME) { const uint64_t ticks = tmr_jiffies(); if (0 == dbg.tick) dbg.tick = tmr_jiffies(); (void)re_fprintf(stderr, "[%09llu] ", ticks - dbg.tick); } (void)re_vfprintf(stderr, fmt, ap); if (dbg.flags & DBG_ANSI && level < DBG_DEBUG) (void)re_fprintf(stderr, "\x1b[;m"); dbg_unlock(); }
void mono_de_unlock (void) { dbg_unlock (); }