2018-03-21 15:22:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2018-03-27 10:53:08 +00:00
|
|
|
#include <time.h>
|
2018-03-22 14:08:51 +00:00
|
|
|
|
2018-03-21 15:22:29 +00:00
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
static const char *level_str[] = {
|
2018-03-24 22:05:42 +00:00
|
|
|
"NONE", /* should never appear in log */
|
2018-03-21 15:22:29 +00:00
|
|
|
"CRITICAL",
|
|
|
|
"ERROR",
|
|
|
|
"INFO",
|
|
|
|
"DEBUG",
|
|
|
|
"TRACE"
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint8_t level = LOG_INFO;
|
|
|
|
|
2018-03-23 12:37:07 +00:00
|
|
|
void rk65c02_loglevel_set(uint8_t l)
|
2018-03-21 15:22:29 +00:00
|
|
|
{
|
|
|
|
level = l;
|
|
|
|
}
|
|
|
|
|
2018-03-23 12:37:07 +00:00
|
|
|
void rk65c02_log(uint8_t l, const char* fmt, ...)
|
2018-03-21 15:22:29 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
2018-03-27 10:53:08 +00:00
|
|
|
struct timespec t;
|
2018-03-21 15:22:29 +00:00
|
|
|
|
|
|
|
if (l > level)
|
|
|
|
return;
|
|
|
|
|
2018-03-27 10:53:08 +00:00
|
|
|
clock_gettime(CLOCK_REALTIME, &t);
|
|
|
|
|
|
|
|
fprintf(stderr, "%ld.%ld %s:\t", t.tv_sec, t.tv_nsec,
|
2018-03-22 14:08:51 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|