Initial import of the bootloader code
[bootloader] / cli / log.c
CommitLineData
9c66c9ff
JM
1#include <stdio.h>
2#include <stdarg.h>
3#include <time.h>
4#include <sys/time.h>
5
6#include "log.h"
7
8int debug = 0;
9
10void logit(int type, const char * format, ...)
11{
12 va_list va;
13 va_start(va, format);
14
15 struct timeval now;
16 gettimeofday(&now, NULL);
17
18 struct tm * now_tm = localtime(&(now.tv_sec));
19
20 if (type == LOG_INFO) {
21 vfprintf(stdout, format, va);
22 fprintf(stdout, "\n");
23 } else
24 if (type == LOG_DEBUG) {
25 if (debug > 0) {
26 fprintf(stderr, "%02d:%02d:%02d.%03d ", now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, (int)(now.tv_usec / 1000));
27 vfprintf(stderr, format, va);
28 fprintf(stderr, "\n");
29 }
30 } else {
31 vfprintf(stderr, format, va);
32 fprintf(stderr, "\n");
33 }
34
35 va_end(va);
36}