1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-06-26 19:29:33 +00:00
rk65c02/src/log.c
Radosław Kujawa 9ff0cb26fc Explicitely cast time to long long ints.
Avoid portability bullshit problems.
2018-03-27 13:30:33 +02:00

43 lines
654 B
C

#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include "log.h"
static const char *level_str[] = {
"NONE", /* should never appear in log */
"CRITICAL",
"ERROR",
"INFO",
"DEBUG",
"TRACE"
};
static uint8_t level = LOG_INFO;
void rk65c02_loglevel_set(uint8_t l)
{
level = l;
}
void rk65c02_log(uint8_t l, const char* fmt, ...)
{
va_list args;
struct timespec t;
if (l > level)
return;
clock_gettime(CLOCK_REALTIME, &t);
fprintf(stderr, "%lld.%lld %s:\t", (long long int) t.tv_sec,
(long long int) t.tv_nsec, level_str[l]);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
}