Skip to content

Commit 0b37771

Browse files
convert to using json for loggin
1 parent 773a1a0 commit 0b37771

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

include/pepdefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/* Number of worker threads in pepsal threads pool */
3535
#define PEPPOOL_THREADS 10
3636

37-
#define PEPLOGGER_INTERVAL (5 * 60)
37+
#define PEPLOGGER_INTERVAL 10
3838

3939
#define PEP_GCC_INTERVAL (15 * 3600)
4040

src/pep.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,33 +245,34 @@ static void logger_fn(void)
245245
{
246246
struct pep_proxy *proxy;
247247
time_t tm;
248-
char ip_src[17], ip_dst[17], timebuf[128];
249-
int i = 1, len;
248+
char ip_src[17], ip_dst[17];
249+
int len, i = 0;
250250

251251
PEP_DEBUG("Logger invoked!");
252252
SYNTAB_LOCK_READ();
253253
tm = time(NULL);
254-
ctime_r(&tm, timebuf);
255-
len = strlen(timebuf);
256-
timebuf[len - 1] = ']';
257-
fprintf(logger.file, "=== [%s ===\n", timebuf);
254+
fprintf(logger.file, "{\"time\":%.f,\"proxies\":[",difftime(tm, (time_t) 0));
258255
syntab_foreach_connection(proxy) {
256+
if (i > 0)
257+
fprintf(logger.file, ",");
258+
259259
toip(ip_src, proxy->src.addr);
260260
toip(ip_dst, proxy->dst.addr);
261-
fprintf(logger.file, "[%d] Proxy %s:%d <-> %s:%d\n", i++,
261+
fprintf(logger.file, "{\"src\":\"%s:%d\",\"dst\":\"%s:%d\",",
262262
ip_src, proxy->src.port, ip_dst, proxy->dst.port);
263-
fprintf(logger.file, " Status: %s\n", conn_stat[proxy->status]);
264-
ctime_r(&proxy->syn_time, timebuf);
265-
fprintf(logger.file, " SYN received: %s", timebuf);
263+
264+
fprintf(logger.file, "\"status\":\"%s\",", conn_stat[proxy->status]);
265+
266+
fprintf(logger.file, "\"sync_recv\":%.f", difftime(proxy->syn_time, (time_t) 0));
267+
266268
if (proxy->last_rxtx != 0) {
267-
ctime_r(&proxy->last_rxtx, timebuf);
268-
fprintf(logger.file, " Last Rx/Tx activity: %s", timebuf);
269+
fprintf(logger.file, ",\"last_act\":\"%s\"", difftime(proxy->last_rxtx, (time_t) 0));
269270
}
270271

272+
fprintf(logger.file, "}");
273+
i++;
271274
}
272-
if (i == 1) {
273-
fprintf(logger.file, " No connections\n");
274-
}
275+
fprintf(logger.file, "]}\n");
275276

276277
SYNTAB_UNLOCK_READ();
277278
fflush(logger.file);

0 commit comments

Comments
 (0)