Changeset 3117


Ignore:
Timestamp:
Sep 20, 2007, 11:33:46 PM (15 years ago)
Author:
charles
Message:

clamp down on the flood of debug messages.

Location:
trunk/libtransmission
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r3105 r3117  
    139139myDebug( const char * file, int line, const tr_handshake * handshake, const char * fmt, ... )
    140140{
    141     va_list args;
    142     const char * addr = tr_peerIoGetAddrStr( handshake->io );
    143     struct evbuffer * buf = evbuffer_new( );
    144     evbuffer_add_printf( buf, "[%s:%d] %s (%p) ", file, line, addr, handshake );
    145     va_start( args, fmt );
    146     evbuffer_add_vprintf( buf, fmt, args );
    147     va_end( args );
    148 
    149     fprintf( stderr, "%s\n", EVBUFFER_DATA(buf) );
    150 
    151     evbuffer_free( buf );
     141    FILE * fp = tr_getLog( );
     142    if( fp != NULL )
     143    {
     144        va_list args;
     145        const char * addr = tr_peerIoGetAddrStr( handshake->io );
     146        struct evbuffer * buf = evbuffer_new( );
     147        evbuffer_add_printf( buf, "[%s:%d] %s (%p) ", file, line, addr, handshake );
     148        va_start( args, fmt );
     149        evbuffer_add_vprintf( buf, fmt, args );
     150        va_end( args );
     151        fprintf( stderr, "%s\n", EVBUFFER_DATA(buf) );
     152        evbuffer_free( buf );
     153    }
    152154}
    153155
  • trunk/libtransmission/peer-mgr.c

    r3116 r3117  
    183183    if( peer->msgs != NULL )
    184184    {
    185 fprintf( stderr, "PUB unsub peer %p from msgs %p\n", peer, peer->msgs );
    186185        tr_peerMsgsUnsubscribe( peer->msgs, peer->msgsTag );
    187186        tr_peerMsgsFree( peer->msgs );
     
    635634            peer->client = peer_id ? tr_clientForId( peer_id ) : NULL;
    636635            peer->peerSupportsEncryption = peerSupportsEncryption ? 1 : 0;
    637             fprintf( stderr, "PUB sub peer %p to msgs %p\n", peer, peer->msgs );
    638636            peer->msgsTag = tr_peerMsgsSubscribe( peer->msgs, msgsCallbackFunc, t );
    639637        }
  • trunk/libtransmission/peer-msgs.c

    r3116 r3117  
    136136myDebug( const char * file, int line, const struct tr_peermsgs * msgs, const char * fmt, ... )
    137137{
    138     va_list args;
    139     const char * addr = tr_peerIoGetAddrStr( msgs->io );
    140     struct evbuffer * buf = evbuffer_new( );
    141     evbuffer_add_printf( buf, "[%s:%d] %s (%p) ", file, line, addr, msgs );
    142     va_start( args, fmt );
    143     evbuffer_add_vprintf( buf, fmt, args );
    144     va_end( args );
    145 
    146     fprintf( stderr, "%s\n", EVBUFFER_DATA(buf) );
    147 
    148     evbuffer_free( buf );
     138    FILE * fp = tr_getLog( );
     139    if( fp != NULL )
     140    {
     141        va_list args;
     142        const char * addr = tr_peerIoGetAddrStr( msgs->io );
     143        struct evbuffer * buf = evbuffer_new( );
     144        evbuffer_add_printf( buf, "[%s:%d] %s (%p) ", file, line, addr, msgs );
     145        va_start( args, fmt );
     146        evbuffer_add_vprintf( buf, fmt, args );
     147        va_end( args );
     148        fprintf( fp, "%s\n", EVBUFFER_DATA(buf) );
     149        evbuffer_free( buf );
     150    }
    149151}
    150152
     
    449451    tr_bencInitStr( tr_bencDictAdd( &val, "v" ), v, 0, 1 );
    450452    buf = tr_bencSaveMalloc( &val,  &len );
    451     tr_bencPrint( &val );
    452453
    453454    msglen = sizeof(tr_msgid) + sizeof(ltep_msgid) + len;
  • trunk/libtransmission/tracker.c

    r3111 r3117  
    266266}
    267267
    268 static int trackerCount = 0;
    269 static int torrentCount = 0;
    270 
    271268static Tracker*
    272269tr_trackerGet( const tr_torrent * tor )
     
    289286
    290287        t = tr_new0( Tracker, 1 );
    291 fprintf( stderr, "TRACKER new tracker %p addr %s; counts are trackers %d torrents %d\n", t, info->primaryAddress, ++trackerCount, torrentCount );
    292288        t->handle = tor->handle;
    293289        t->primaryAddress = tr_strdup( info->primaryAddress );
     
    364360    tr_ptrArrayRemoveSorted( t->scraping, tor, torrentCompare );
    365361
    366 fprintf( stderr, "TRACKER freeing torrent %p name %s; counts are trackers %d torrents %d\n", tor, tor->torrent->info.name, trackerCount, --torrentCount );
    367362    tr_timerFree( &tor->scrapeTimer );
    368363    tr_timerFree( &tor->reannounceTimer );
     
    379374        tr_ptrArrayRemoveSorted( getTrackerLookupTable( ), t, trackerCompare );
    380375
    381 fprintf( stderr, "TRACKER freeing tracker %p; counts are trackers %d torrents %d\n", t, --trackerCount, torrentCount );
    382 
    383376        if( t->connection != NULL )
    384377            evhttp_connection_free( t->connection );
     
    420413    /* create a new Torrent and queue it for scraping */
    421414    tor = tr_new0( Torrent, 1 );
    422 fprintf( stderr, "TRACKER new torrent %p name %s; counts are trackers %d torrents %d\n", tor, torrent->info.name, trackerCount, ++torrentCount );
    423415    tor->publisher = tr_publisherNew( );
    424416    tor->tracker = t;
  • trunk/libtransmission/transmission.c

    r3111 r3117  
    235235}
    236236
    237 
    238 void tr_torrentRates( tr_handle * h, float * dl, float * ul )
     237void
     238tr_torrentRates( tr_handle * h, float * dl, float * ul )
    239239{
    240240    tr_torrent * tor;
     
    254254}
    255255
    256 int tr_torrentCount( tr_handle * h )
     256int
     257tr_torrentCount( tr_handle * h )
    257258{
    258259    return h->torrentCount;
    259260}
    260261
    261 void tr_torrentIterate( tr_handle * h, tr_callback_t func, void * d )
     262void
     263tr_torrentIterate( tr_handle * h, tr_callback_t func, void * d )
    262264{
    263265    tr_torrent * tor, * next;
     
    274276{
    275277    tr_handle * h = vh;
    276 fprintf( stderr, "in tr_closeImpl\n" );
    277278    tr_peerMgrFree( h->peerMgr );
    278 fprintf( stderr, "calling mgr free\n" );
    279279
    280280    tr_rcClose( h->upload );
    281281    tr_rcClose( h->download );
    282282
    283 fprintf( stderr, "calling shared close\n" );
    284283    tr_sharedClose( h->shared );
    285 fprintf( stderr, "calling fd close\n" );
    286284    tr_fdClose();
    287285
    288 fprintf( stderr, "setting h->closed to TRUE\n" );
    289286    h->isClosed = TRUE;
    290287}
     
    292289tr_close( tr_handle * h )
    293290{
    294     fprintf( stderr, "torrentCount is %d\n", h->torrentCount );
    295291    assert( tr_torrentCount( h ) == 0 );
    296292
    297 fprintf( stderr, "here I am in tr_close...\n" );
    298293    tr_runInEventThread( h, tr_closeImpl, h );
    299294    while( !h->isClosed )
     
    308303    free( h->tag );
    309304    free( h );
     305    fprintf( stderr, "tr_close() completed.\n" );
    310306}
    311307
  • trunk/libtransmission/trevent.c

    r3111 r3117  
    212212
    213213    event_dispatch( );
    214 fprintf( stderr, "w00t!!!!!!!!!!!!!!!!!!!\n" );
    215214
    216215    tr_lockFree( eh->lock );
  • trunk/libtransmission/utils.c

    r3105 r3117  
    6262}
    6363
    64 void tr_setMessageLevel( int level )
     64FILE*
     65tr_getLog( void )
     66{
     67    static int initialized = FALSE;
     68    static FILE * file= NULL;
     69
     70    if( !initialized )
     71    {
     72        const char * str = getenv( "TR_DEBUG_FD" );
     73        int fd;
     74        if( str && *str )
     75            fd = atoi( str );
     76        switch( fd ) {
     77            case 1: file = stdout; break;
     78            case 2: file = stderr; break;
     79            default: file = NULL; break;
     80        }
     81        initialized = TRUE;
     82    }
     83
     84    return file;
     85}
     86
     87void
     88tr_setMessageLevel( int level )
    6589{
    6690    tr_msgInit();
     
    121145    va_list       args1, args2;
    122146    tr_msg_list * newmsg;
    123     int             len1, len2;
     147    int           len1, len2;
     148    FILE        * fp;
    124149
    125150    assert( NULL != messageLock );
    126151    tr_lockLock( messageLock );
     152
     153    fp = tr_getLog( );
    127154
    128155    if( !messageLevel )
     
    149176                             args1, args2 );
    150177                va_end( args2 );
     178                if( fp != NULL )
     179                    fprintf( fp, "%s\n", newmsg->message );
    151180                if( NULL == newmsg->message )
    152181                {
     
    162191        else
    163192        {
    164             vfprintf( stderr, msg, args1 );
    165             fputc( '\n', stderr );
    166             fflush( stderr );
     193            if( fp == NULL )
     194                fp = stderr;
     195            vfprintf( fp, msg, args1 );
     196            fputc( '\n', fp );
     197            fflush( fp );
    167198        }
    168199        va_end( args1 );
  • trunk/libtransmission/utils.h

    r3105 r3117  
    2929#include <stdarg.h>
    3030#include <stddef.h> /* for size_t */
     31#include <stdio.h> /* FILE* */
    3132
    3233void tr_msgInit( void );
     
    3637#define tr_dbg( a... ) tr_msg( TR_MSG_DBG, ## a )
    3738void tr_msg  ( int level, char * msg, ... );
     39FILE* tr_getLog( void );
    3840
    3941int  tr_rand ( int );
Note: See TracChangeset for help on using the changeset viewer.