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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include <config.h>
#include "info.h"
#include <time.h>
Info::Info() {
pthread_mutex_init (&mutex, NULL);
}
void Info::log(char *fmt, ...)
{
FILE *fp;
char buf[1024];
pthread_mutex_lock(&mutex);
fp = fopen(log_filename.c_str(), "a");
if(!fp) {
fprintf(stderr, "Log file %s could not be opened in writemode.\n", log_filename.c_str());
return;
}
va_list argp;
va_start(argp, fmt);
vsprintf(buf, fmt, argp);
va_end(argp);
time_t t = time(NULL);
char sdate[32];
memset(sdate, 0, sizeof(sdate));
strftime(sdate, sizeof(sdate), "%d %b %H:%M:%S", localtime(&t));
fprintf(fp, "%s miav[%d] %s\n", sdate, getpid(), buf);
fclose(fp);
pthread_mutex_unlock(&mutex);
}
|