Add a simple debug logging mechanism.

This commit is contained in:
okan
2018-02-02 13:40:55 +00:00
parent 9bf750b054
commit 34e15dbd7a
2 changed files with 40 additions and 0 deletions

30
util.c
View File

@@ -31,6 +31,8 @@
#include "calmwm.h"
static void log_msg(const char *, va_list);
void
u_spawn(char *argstr)
{
@@ -104,3 +106,31 @@ u_argv(char * const *argv)
}
return(p);
}
static void
log_msg(const char *msg, va_list ap)
{
char *fmt;
if (asprintf(&fmt, "%s\n", msg) == -1) {
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
} else {
vfprintf(stderr, fmt, ap);
free(fmt);
}
fflush(stderr);
}
void
log_debug(const char *func, const char *msg, ...)
{
char *fmt;
va_list ap;
va_start(ap, msg);
if (asprintf(&fmt, "%s: %s", func, msg) == -1)
exit(1);
log_msg(fmt, ap);
va_end(ap);
}