From f4409df68abe9a27686a157ffa8da33603fc91ad Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Thu, 12 Nov 2009 10:18:27 +0000 Subject: Allow logging of completed events to syslog --- ot_stats.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ot_stats.c') diff --git a/ot_stats.c b/ot_stats.c index 4f6b620..a976713 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -14,6 +14,9 @@ #include #include #include +#ifdef WANT_SYSLOGS +#include +#endif /* Libowfat */ #include "byte.h" @@ -637,6 +640,13 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event if( proto == FLAG_TCP ) ot_overall_tcp_connects++; else ot_overall_udp_connects++; break; case EVENT_COMPLETED: +#ifdef WANT_SYSLOGS + if( event_data) { + char hex_out[42]; + to_hex( hex_out, (uint8_t*)event_data ); + syslog( LOG_INFO, "event=completed info_hash=%s", hex_out ); + } +#endif ot_overall_completed++; break; case EVENT_SCRAPE: @@ -715,10 +725,17 @@ static pthread_t thread_id; void stats_init( ) { ot_start_time = g_now_seconds; pthread_create( &thread_id, NULL, stats_worker, NULL ); +#ifdef WANT_SYSLOGS + openlog( "opentracker", 0, LOG_USER ); + setlogmask(LOG_UPTO(LOG_INFO)); +#endif } void stats_deinit( ) { pthread_cancel( thread_id ); +#ifdef WANT_SYSLOGS + closelog(); +#endif } const char *g_version_stats_c = "$Source$: $Revision$\n"; -- cgit v1.2.3