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
40
41
42
43
44
|
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <log.h>
#define LOG_OUT stdout
#define ERR_OUT stderr
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
__attribute__((__format__(__printf__, 2, 0))) void
__logln(const char *func, const char *format, ...)
{
pthread_mutex_lock(&mutex);
fprintf(LOG_OUT, "[LOG] %s: ", func);
va_list ap;
va_start(ap, format);
vfprintf(LOG_OUT, format, ap);
va_end(ap);
fprintf(LOG_OUT, "\n");
pthread_mutex_unlock(&mutex);
}
__attribute__((__format__(__printf__, 2, 0))) void
__errln(const char *func, const char *format, ...)
{
pthread_mutex_lock(&mutex);
fprintf(ERR_OUT, "[ERR] %s: ", func);
va_list ap;
va_start(ap, format);
vfprintf(ERR_OUT, format, ap);
va_end(ap);
fprintf(ERR_OUT, "\n");
pthread_mutex_unlock(&mutex);
}
|