1 |
#include "eef.h" |
2 |
#include <time.h> |
3 |
|
4 |
EES_RC eef_log(int priority, const char* format, ...){ |
5 |
va_list args; |
6 |
/*time_t _time;*/ |
7 |
/*struct tm * _time_s;*/ |
8 |
/*char _strf_fmt[MAX_TIME_STRING_SIZE];*/ |
9 |
|
10 |
/*_time = time(NULL);*/ |
11 |
/*_time_s = localtime(&_time);*/ |
12 |
/*strftime(_strf_fmt, MAX_TIME_STRING_SIZE, "%G", _time_s);*/ |
13 |
|
14 |
va_start(args, format); |
15 |
if(priority == LOG_ERR){ |
16 |
vfprintf(stderr, append_newline(format), args); |
17 |
} |
18 |
va_end(args); |
19 |
#if ENABLE_DEBUG |
20 |
va_start(args, format); |
21 |
if(priority == LOG_DEBUG){ |
22 |
vfprintf(stdout, append_newline(format), args); |
23 |
} |
24 |
va_end(args); |
25 |
#endif |
26 |
va_start(args, format); |
27 |
vsyslog(priority, format, args); |
28 |
va_end(args); |
29 |
return 0; |
30 |
} |
31 |
|
32 |
const char* append_newline(const char* string){ |
33 |
char* mutable_string; |
34 |
if(!strchr(string, '\n')){ |
35 |
mutable_string = strdup(string); |
36 |
mutable_string = realloc(mutable_string, (sizeof(char) * (strlen(string)+1))); |
37 |
strncat(mutable_string, "\n", 1); |
38 |
return mutable_string; |
39 |
} |
40 |
return string; |
41 |
} |