diff options
| author | erdgeist <> | 2009-11-12 10:18:27 +0000 |
|---|---|---|
| committer | erdgeist <> | 2009-11-12 10:18:27 +0000 |
| commit | f4409df68abe9a27686a157ffa8da33603fc91ad (patch) | |
| tree | 6c99371a0fe2e12230c9c22bd263367251877762 /ot_stats.c | |
| parent | b1bf030f922685b2613c7826fac306b6c2a82552 (diff) | |
Allow logging of completed events to syslog
Diffstat (limited to 'ot_stats.c')
| -rw-r--r-- | ot_stats.c | 17 |
1 files changed, 17 insertions, 0 deletions
| @@ -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; | |||
| 715 | void stats_init( ) { | 725 | void 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 | ||
| 720 | void stats_deinit( ) { | 734 | void stats_deinit( ) { |
| 721 | pthread_cancel( thread_id ); | 735 | pthread_cancel( thread_id ); |
| 736 | #ifdef WANT_SYSLOGS | ||
| 737 | closelog(); | ||
| 738 | #endif | ||
| 722 | } | 739 | } |
| 723 | 740 | ||
| 724 | const char *g_version_stats_c = "$Source$: $Revision$\n"; | 741 | const char *g_version_stats_c = "$Source$: $Revision$\n"; |
