diff options
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 70 |
1 files changed, 51 insertions, 19 deletions
@@ -58,11 +58,41 @@ jalv_strjoin(const char* const a, const char* const b) } int -jalv_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...) +jalv_vlog(const JalvLogLevel level, const char* const fmt, va_list ap) +{ + bool fancy = false; + switch (level) { + case JALV_LOG_ERR: + fancy = jalv_ansi_start(stderr, 31); + fprintf(stderr, "error: "); + break; + case JALV_LOG_WARNING: + fancy = jalv_ansi_start(stderr, 33); + fprintf(stderr, "warning: "); + break; + case JALV_LOG_DEBUG: + fancy = jalv_ansi_start(stderr, 32); + fprintf(stderr, "trace: "); + break; + } + + const int st = vfprintf(stderr, fmt, ap); + + if (fancy) { + jalv_ansi_reset(stderr); + } + + return st; +} + +int +jalv_log(const JalvLogLevel level, const char* const fmt, ...) { va_list args; va_start(args, fmt); - const int ret = jalv_vprintf(handle, type, fmt, args); + + const int ret = jalv_vlog(level, fmt, args); + va_end(args); return ret; } @@ -70,29 +100,31 @@ jalv_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...) int jalv_vprintf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, va_list ap) { - // TODO: Lock - Jalv* jalv = (Jalv*)handle; - bool fancy = true; + Jalv* const jalv = (Jalv*)handle; + if (type == jalv->urids.log_Trace && jalv->opts.trace) { - jalv_ansi_start(stderr, 32); - fprintf(stderr, "trace: "); - } else if (type == jalv->urids.log_Error) { - jalv_ansi_start(stderr, 31); - fprintf(stderr, "error: "); - } else if (type == jalv->urids.log_Warning) { - jalv_ansi_start(stderr, 33); - fprintf(stderr, "warning: "); - } else { - fancy = false; + return jalv_vlog(JALV_LOG_DEBUG, fmt, ap); } - const int st = vfprintf(stderr, fmt, ap); + if (type == jalv->urids.log_Error) { + return jalv_vlog(JALV_LOG_ERR, fmt, ap); + } - if (fancy) { - jalv_ansi_reset(stderr); + if (type == jalv->urids.log_Warning) { + return jalv_vlog(JALV_LOG_WARNING, fmt, ap); } - return st; + return vfprintf(stderr, fmt, ap); +} + +int +jalv_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + const int ret = jalv_vprintf(handle, type, fmt, args); + va_end(args); + return ret; } bool |