@@ -245,33 +245,34 @@ static void logger_fn(void)
245
245
{
246
246
struct pep_proxy * proxy ;
247
247
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 ;
250
250
251
251
PEP_DEBUG ("Logger invoked!" );
252
252
SYNTAB_LOCK_READ ();
253
253
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 ));
258
255
syntab_foreach_connection (proxy ) {
256
+ if (i > 0 )
257
+ fprintf (logger .file , "," );
258
+
259
259
toip (ip_src , proxy -> src .addr );
260
260
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\"," ,
262
262
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
+
266
268
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 ));
269
270
}
270
271
272
+ fprintf (logger .file , "}" );
273
+ i ++ ;
271
274
}
272
- if (i == 1 ) {
273
- fprintf (logger .file , " No connections\n" );
274
- }
275
+ fprintf (logger .file , "]}\n" );
275
276
276
277
SYNTAB_UNLOCK_READ ();
277
278
fflush (logger .file );
0 commit comments