summaryrefslogtreecommitdiff
path: root/ot_stats.c
diff options
context:
space:
mode:
authorerdgeist <>2009-11-12 10:18:27 +0000
committererdgeist <>2009-11-12 10:18:27 +0000
commitf4409df68abe9a27686a157ffa8da33603fc91ad (patch)
tree6c99371a0fe2e12230c9c22bd263367251877762 /ot_stats.c
parentb1bf030f922685b2613c7826fac306b6c2a82552 (diff)
Allow logging of completed events to syslog
Diffstat (limited to 'ot_stats.c')
-rw-r--r--ot_stats.c17
1 files changed, 17 insertions, 0 deletions
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 @@
14#include <pthread.h> 14#include <pthread.h>
15#include <unistd.h> 15#include <unistd.h>
16#include <inttypes.h> 16#include <inttypes.h>
17#ifdef WANT_SYSLOGS
18#include <syslog.h>
19#endif
17 20
18/* Libowfat */ 21/* Libowfat */
19#include "byte.h" 22#include "byte.h"
@@ -637,6 +640,13 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
637 if( proto == FLAG_TCP ) ot_overall_tcp_connects++; else ot_overall_udp_connects++; 640 if( proto == FLAG_TCP ) ot_overall_tcp_connects++; else ot_overall_udp_connects++;
638 break; 641 break;
639 case EVENT_COMPLETED: 642 case EVENT_COMPLETED:
643#ifdef WANT_SYSLOGS
644 if( event_data) {
645 char hex_out[42];
646 to_hex( hex_out, (uint8_t*)event_data );
647 syslog( LOG_INFO, "event=completed info_hash=%s", hex_out );
648 }
649#endif
640 ot_overall_completed++; 650 ot_overall_completed++;
641 break; 651 break;
642 case EVENT_SCRAPE: 652 case EVENT_SCRAPE:
@@ -715,10 +725,17 @@ static pthread_t thread_id;
715void stats_init( ) { 725void stats_init( ) {
716 ot_start_time = g_now_seconds; 726 ot_start_time = g_now_seconds;
717 pthread_create( &thread_id, NULL, stats_worker, NULL ); 727 pthread_create( &thread_id, NULL, stats_worker, NULL );
728#ifdef WANT_SYSLOGS
729 openlog( "opentracker", 0, LOG_USER );
730 setlogmask(LOG_UPTO(LOG_INFO));
731#endif
718} 732}
719 733
720void stats_deinit( ) { 734void stats_deinit( ) {
721 pthread_cancel( thread_id ); 735 pthread_cancel( thread_id );
736#ifdef WANT_SYSLOGS
737 closelog();
738#endif
722} 739}
723 740
724const char *g_version_stats_c = "$Source$: $Revision$\n"; 741const char *g_version_stats_c = "$Source$: $Revision$\n";