1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/param.h>
#include <time.h>
#include "getstream.h"
int loglevel=LOG_ERROR;
void logwrite_inc_level() {
loglevel++;
}
void logwrite(int level, const char *format, ...) {
va_list pvar;
char logbuffer[MAXPATHLEN];
char timedate[64];
struct timeval tv;
struct tm *tm;
time_t *t=&tv.tv_sec;
if (level > loglevel)
return;
va_start (pvar, format);
vsnprintf(logbuffer, sizeof(logbuffer), format, pvar);
va_end (pvar);
gettimeofday(&tv, NULL);
tm=localtime(t);
strftime(timedate, sizeof(timedate), "%Y-%m-%d %H:%M:%S", tm);
printf("%s.%03d %s\n",
timedate,
(int) tv.tv_usec/1000,
logbuffer);
}
|