#include "print.h"
#include "jove.h"
#include "string.h"
#include "device/serial.h"
#include "klib/format.h"
#include "klib/spinlock.h"
static spinlock_t s_print_lock;
static char s_print_buffer[PRINT_BUFFERW];
static char *s_print_level_str[PRINT_ERROR + 1] = {
"[D] %s/%s:%i | ",
"[I] ",
"[W] %s/%s:%i | ",
"[!!E!!] %s/%s:%i | "
};
void
_plogvf(const char *file, const char *func, int line, int lvl, const char *fmt, va_list ap)
{
spinlock_acquire(s_print_lock);
char *buf = sfmt(s_print_buffer, PRINT_BUFFERW, s_print_level_str[lvl],
file, func, line);
size_t prew = strlen(buf);
svfmt(&buf[prew], PRINT_BUFFERW - 128, fmt, ap);
serial_write(&COM1, buf, strlen(buf));
spinlock_release(s_print_lock);
}
void
_plogf(const char *file, const char *func, int line, int lvl, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_plogvf(file, func, line, lvl, fmt, ap);
va_end(ap);
}