2018-03-21 15:22:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2018-03-22 14:08:51 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2018-03-21 15:22:29 +00:00
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
static const char *level_str[] = {
|
|
|
|
"",
|
|
|
|
"CRITICAL",
|
|
|
|
"ERROR",
|
|
|
|
"INFO",
|
|
|
|
"DEBUG",
|
|
|
|
"TRACE"
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint8_t level = LOG_INFO;
|
|
|
|
|
|
|
|
void rk6502_loglevel_set(uint8_t l)
|
|
|
|
{
|
|
|
|
level = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rk6502_log(uint8_t l, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2018-03-22 14:08:51 +00:00
|
|
|
struct timeval t;
|
|
|
|
|
|
|
|
gettimeofday(&t, NULL);
|
2018-03-21 15:22:29 +00:00
|
|
|
|
|
|
|
if (l > level)
|
|
|
|
return;
|
|
|
|
|
2018-03-22 14:08:51 +00:00
|
|
|
fprintf(stderr, "%ld %s:\t", (t.tv_sec * 1000000 + t.tv_usec),
|
|
|
|
level_str[l]);
|
2018-03-21 15:22:29 +00:00
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|