-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogfile.cpp
More file actions
35 lines (28 loc) · 810 Bytes
/
Copy pathlogfile.cpp
File metadata and controls
35 lines (28 loc) · 810 Bytes
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
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
static pid_t pid = -1;
static FILE *__debug = 0;
void dbg(const char *msg, ...);
void dbg(const char *msg, ...)
{
if (pid == -1)
pid = getpid();
if (!__debug) {
__debug = fopen("/var/log/debug.txt", "ab");
fprintf(__debug, "===============================================================================\n");
}
struct timeval tv;
gettimeofday(&tv, NULL);
char time[64];
strftime(time, sizeof(time), "%y.%m.%d %H:%M:%S", localtime(&tv.tv_sec));
fprintf(__debug, "%s.%06lu [%d]", time, tv.tv_usec, pid);
va_list args;
va_start(args, msg);
vfprintf(__debug, msg, args);
va_end(args);
fprintf(__debug, "\n");
fflush(__debug);
}