-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.c
65 lines (52 loc) · 1.18 KB
/
log.c
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
#include <time.h>
#include "cba.h"
#include "utils.h"
/*
Name is a bit misleading - this uses cba to log internal cscan events.
Original idea was to make info() print to cba, but to make tid=0 print to stderr if no file
maybe that was better?
*/
#define STATS_EVERY 10
#define STAT_TIME 11
#define EVENT 20
#define CANARY_FAIL 21
#define CANARY_FAIL_RESPONSE 22
void log_stats_every(int stats_every)
{
if (cba_has_file())
{
cba_code(STATS_EVERY);
cba_int32(stats_every);
}
}
void log_stats(int packets, int results, int new_events, int new_results)
{
info("%d packets sent, %d results received, %d new events", packets, results, new_events);
if (cba_has_file())
{
cba_code(STAT_TIME); cba_int64(time(NULL));
cba_int32(new_events); cba_int32(new_results);
}
}
void log_canary_fail(int got_reply)
{
info("canary FAIL: %s", got_reply ? "invalid response" : "timed out");
if (cba_has_file())
{
cba_bit(got_reply ? CANARY_FAIL_RESPONSE : CANARY_FAIL);
}
}
void log_event(char *fmt, ...)
{
va_list args, args2;
va_start(args, fmt);
va_end(args);
va_copy(args2, args);
va_end(args2);
vinfo(fmt, args);
if (cba_has_file())
{
cba_code(EVENT);
cba_vstr(fmt, args2);
}
}