diff --git a/gtk/msgwin.c b/gtk/msgwin.c index de905db3c..759c1f216 100644 --- a/gtk/msgwin.c +++ b/gtk/msgwin.c @@ -110,7 +110,9 @@ msgwin_update( void ) case TR_MSG_DBG: tag = "debug"; break; } - line = g_strdup_printf( "%02i:%02i:%02i %s\n", tm->tm_hour, tm->tm_min, tm->tm_sec, ii->message ); + line = ( ii->name != NULL ) + ? g_strdup_printf( "%02i:%02i:%02i [%s] %s\n", tm->tm_hour, tm->tm_min, tm->tm_sec, ii->name, ii->message ) + : g_strdup_printf( "%02i:%02i:%02i %s\n", tm->tm_hour, tm->tm_min, tm->tm_sec, ii->message ); len = strlen( line ); gtk_text_buffer_get_end_iter( textbuf, &mark_end ); diff --git a/libtransmission/fastresume.c b/libtransmission/fastresume.c index 36fcee251..e9d493bac 100644 --- a/libtransmission/fastresume.c +++ b/libtransmission/fastresume.c @@ -188,7 +188,7 @@ tr_fastResumeSave( const tr_torrent * tor ) fastResumeFileName( path, sizeof path, tor, 1 ); file = fopen( path, "wb+" ); if( !file ) { - tr_err( _( "Couldn't open \"%s\": %s" ), path, tr_strerror( errno ) ); + tr_torerr( tor, _( "Couldn't open \"%s\": %s" ), path, tr_strerror( errno ) ); return; } @@ -323,8 +323,6 @@ tr_fastResumeSave( const tr_torrent * tor ) } fclose( file ); - - /*tr_dbg( "Wrote resume file for \"%s\"", tor->info.name );*/ } /*** @@ -419,7 +417,7 @@ parseProgress( tr_torrent * tor, tr_torrentSetFileChecked( tor, i, TRUE ); else { tr_torrentSetFileChecked( tor, i, FALSE ); - tr_dbg( _( "Torrent \"%s\" needs to be verified" ), tor->info.files[i].name ); + tr_tordbg( tor, _( "Torrent needs to be verified" ) ); } } free( curMTimes ); @@ -542,7 +540,7 @@ parsePeers( tr_torrent * tor, const uint8_t * buf, uint32_t len ) tr_peerMgrAddPex( tor->handle->peerMgr, tor->info.hash, TR_PEER_FROM_CACHE, &pex ); } - tr_dbg( _( "Loaded %i peers from resume file" ), count ); + tr_tordbg( tor, _( "Loaded %i peers from resume file" ), count ); ret = TR_FR_PEERS; } @@ -588,7 +586,7 @@ parseVersion1( tr_torrent * tor, const uint8_t * buf, const uint8_t * end, case FR_ID_PEERS: ret |= parsePeers( tor, buf, len ); break; case FR_ID_MAX_PEERS: ret |= parseConnections( tor, buf, len ); break; case FR_ID_DESTINATION: ret |= parseDestination( tor, buf, len ); break; - default: tr_dbg( _( "Skipping unknown resume code %d" ), (int)id ); break; + default: tr_tordbg( tor, _( "Skipping unknown resume code %d" ), (int)id ); break; } buf += len; @@ -632,7 +630,7 @@ fastResumeLoadImpl ( tr_torrent * tor, if( !buf ) /* %s is the torrent name */ - tr_inf( _( "Couldn't read resume file for \"%s\"" ), tor->info.name ); + tr_torinf( tor, _( "Couldn't read resume file for \"%s\"" ), tor->info.name ); else { const uint8_t * walk = buf; const uint8_t * end = walk + size; @@ -643,7 +641,7 @@ fastResumeLoadImpl ( tr_torrent * tor, ret |= parseVersion1 ( tor, walk, end, fieldsToLoad ); else /* %s is the torrent name */ - tr_inf( _( "Skipping invalid resume file for \"%s\"" ), tor->info.name ); + tr_torinf( tor, _( "Skipping invalid resume file for \"%s\"" ), tor->info.name ); } tr_free( buf ); diff --git a/libtransmission/natpmp.c b/libtransmission/natpmp.c index f3b536c23..8ed1d7455 100644 --- a/libtransmission/natpmp.c +++ b/libtransmission/natpmp.c @@ -65,11 +65,11 @@ static void logVal( const char * func, int ret ) { if( ret==NATPMP_TRYAGAIN ) - tr_dbg( _( "%s: %s responded 'try again'" ), getKey(), func ); + tr_ndbg( getKey(), _( "%s responded 'try again'" ), func ); else if( ret >= 0 ) - tr_dbg( _( "%s: %s succeeded (%d)" ), getKey(), func, ret ); + tr_ndbg( getKey(), _( "%s succeeded (%d)" ), func, ret ); else - tr_err( _( "%s: %s failed (%d): %s (%d)" ), getKey(), func, ret, tr_strerror(errno), errno ); + tr_nerr( getKey(), _( "%s failed (%d): %s (%d)" ), func, ret, tr_strerror(errno), errno ); } struct tr_natpmp* @@ -109,8 +109,8 @@ setCommandTime( struct tr_natpmp * nat ) static void setErrorState( struct tr_natpmp * nat ) { - tr_err( _( "%s: If your router supports NAT-PMP, please make sure NAT-PMP is enabled!" ), getKey() ); - tr_err( _( "%s: NAT-PMP port forwarding unsuccessful, trying UPnP next" ), getKey() ); + tr_nerr( getKey(), _( "If your router supports NAT-PMP, please make sure NAT-PMP is enabled!" ) ); + tr_nerr( getKey(), _( "NAT-PMP port forwarding unsuccessful, trying UPnP next" ) ); nat->state = TR_NATPMP_ERR; } @@ -136,7 +136,7 @@ tr_natpmpPulse( struct tr_natpmp * nat, int port, int isEnabled ) const int val = readnatpmpresponseorretry( &nat->natpmp, &response ); logVal( "readnatpmpresponseorretry", val ); if( val >= 0 ) { - tr_inf( _( "%s: found public address %s" ), getKey(), inet_ntoa( response.publicaddress.addr ) ); + tr_ninf( getKey(), _( "found public address %s" ), inet_ntoa( response.publicaddress.addr ) ); nat->state = TR_NATPMP_IDLE; } else if( val != NATPMP_TRYAGAIN ) { setErrorState( nat ); @@ -163,7 +163,7 @@ tr_natpmpPulse( struct tr_natpmp * nat, int port, int isEnabled ) const int val = readnatpmpresponseorretry( &nat->natpmp, &resp ); logVal( "readnatpmpresponseorretry", val ); if( val >= 0 ) { - tr_inf( _( "%s: no longer forwarding port %d" ), getKey(), nat->port ); + tr_ninf( getKey(), _( "no longer forwarding port %d" ), nat->port ); nat->state = TR_NATPMP_IDLE; nat->port = -1; nat->isMapped = 0; @@ -199,7 +199,7 @@ tr_natpmpPulse( struct tr_natpmp * nat, int port, int isEnabled ) nat->isMapped = 1; nat->renewTime = time( NULL ) + LIFETIME_SECS; nat->port = resp.newportmapping.privateport; - tr_inf( _( "%s: port %d forwarded successfully" ), getKey(), nat->port ); + tr_ninf( getKey(), _( "port %d forwarded successfully" ), nat->port ); } else if( val != NATPMP_TRYAGAIN ) { setErrorState( nat ); } diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 0a01860cb..bd28a6b20 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -972,7 +972,7 @@ parseUtPex( tr_peermsgs * msgs, int msglen, struct evbuffer * inbuf ) && (( sub = tr_bencDictFindType( &val, "added", TYPE_STR )))) { const int n = sub->val.s.i / 6 ; - tr_inf( _( "Torrent \"%s\" got %d peers from peer exchange" ), msgs->torrent->info.name, n ); + tr_torinf( msgs->torrent, _( "Got %d peers from peer exchange" ), n ); tr_peerMgrAddPeers( msgs->handle->peerMgr, msgs->torrent->info.hash, TR_PEER_FROM_PEX, diff --git a/libtransmission/shared.c b/libtransmission/shared.c index 09d178e1d..77516b8da 100644 --- a/libtransmission/shared.c +++ b/libtransmission/shared.c @@ -93,7 +93,7 @@ natPulse( tr_shared * s ) if( status == TR_NAT_TRAVERSAL_ERROR ) status = tr_upnpPulse( s->upnp, port, isEnabled ); if( status != s->natStatus ) { - tr_inf( _( "%s: state changed from \"%s\" to \"%s\"" ), getKey(), getNatStateStr(s->natStatus), getNatStateStr(status) ); + tr_ninf( getKey(), _( "state changed from \"%s\" to \"%s\"" ), getNatStateStr(s->natStatus), getNatStateStr(status) ); s->natStatus = status; } } @@ -103,7 +103,7 @@ incomingPeersPulse( tr_shared * s ) { if( s->bindSocket >= 0 && ( s->bindPort != s->publicPort ) ) { - tr_inf( _( "%s: Closing port %d" ), getKey(), s->bindPort ); + tr_ninf( getKey(), _( "Closing port %d" ), s->bindPort ); tr_netClose( s->bindSocket ); s->bindSocket = -1; } @@ -114,13 +114,13 @@ incomingPeersPulse( tr_shared * s ) errno = 0; socket = tr_netBindTCP( s->publicPort ); if( socket >= 0 ) { - tr_inf( _( "%s: Opened port %d to listen for incoming peer connections" ), getKey(), s->publicPort ); + tr_ninf( getKey(), _( "Opened port %d to listen for incoming peer connections" ), s->publicPort ); s->bindPort = s->publicPort; s->bindSocket = socket; listen( s->bindSocket, 5 ); } else { - tr_err( _( "%s: Couldn't open port %d to listen for incoming peer connections (errno %d - %s)" ), - getKey(), s->publicPort, errno, tr_strerror(errno) ); + tr_nerr( getKey(), _( "Couldn't open port %d to listen for incoming peer connections (errno %d - %s)" ), + s->publicPort, errno, tr_strerror(errno) ); s->bindPort = -1; s->bindSocket = -1; } @@ -157,7 +157,7 @@ sharedPulse( void * vshared ) } else if( ( shared->natStatus == TR_NAT_TRAVERSAL_ERROR ) || ( shared->natStatus == TR_NAT_TRAVERSAL_UNMAPPED ) ) { - tr_dbg( _( "%s: stopped" ), getKey() ); + tr_ndbg( getKey(), _( "Stopped" ) ); shared->h->shared = NULL; tr_netClose( shared->bindSocket ); tr_natpmpClose( shared->natpmp ); diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 0e2e710fa..8eea6a530 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -157,13 +157,13 @@ onTrackerResponse( void * tracker UNUSED, void * vevent, void * user_data ) break; case TR_TRACKER_WARNING: - tr_err( _( "Tracker warning: %s" ), event->text ); + tr_torerr( tor, _( "Tracker warning: %s" ), event->text ); tor->error = TR_ERROR_TC_WARNING; strlcpy( tor->errorString, event->text, sizeof(tor->errorString) ); break; case TR_TRACKER_ERROR: - tr_err( _( "Tracker error: %s" ), event->text ); + tr_torerr( tor, _( "Tracker error: %s" ), event->text ); tor->error = TR_ERROR_TC_ERROR; strlcpy( tor->errorString, event->text, sizeof(tor->errorString) ); break; @@ -875,8 +875,8 @@ freeTorrent( tr_torrent * tor ) assert( h->torrentCount >= 1 ); h->torrentCount--; - tr_inf( _( "Closing torrent %s; %d torrents left" ), - tor->info.name, h->torrentCount ); + tr_torinf( tor, _( "Closing torrent %s; %d torrents left" ), + h->torrentCount ); tr_metainfoFree( inf ); tr_free( tor ); diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index f29323bd8..bab6cce9b 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -262,7 +262,7 @@ publishNewPeers( tr_tracker * t, int count, uint8_t * peers ) event.messageType = TR_TRACKER_PEERS; event.peerCount = count; event.peerCompact = peers; - tr_dbg( "Torrent \"%s\" got %d new peers", t->name, count ); + tr_ndbg( t->name, "Torrent got %d new peers", t->name, count ); if( count ) tr_publisherPublish( t->publisher, t, &event ); } @@ -412,9 +412,8 @@ onTrackerResponse( struct evhttp_request * req, void * vhash ) if( req && req->response_code_line ) strlcpy( t->lastAnnounceResponse, req->response_code_line, sizeof( t->lastAnnounceResponse ) ); - tr_dbg( "Torrent \"%s\" tracker response: %s", - t->name, - ( req ? req->response_code_line : "(null)") ); + tr_ndbg( t->name, "tracker response: %s", + ( req ? req->response_code_line : "(null)") ); if( req && ( req->response_code == HTTP_OK ) ) { @@ -573,10 +572,8 @@ onScrapeResponse( struct evhttp_request * req, void * vhash ) if( req && req->response_code_line ) strlcpy( t->lastScrapeResponse, req->response_code_line, sizeof( t->lastScrapeResponse ) ); - tr_dbg( "Got scrape response for '%s': %s", - t->name, - ( ( req && req->response_code_line ) ? req->response_code_line - : "(null)") ); + tr_ndbg( t->name, "Got scrape response: \"%s\"", + ( ( req && req->response_code_line ) ? req->response_code_line : "(null)") ); if( req && ( req->response_code == HTTP_OK ) ) { @@ -612,9 +609,8 @@ onScrapeResponse( struct evhttp_request * req, void * vhash ) if(( tmp = tr_bencDictFind( flags, "min_request_interval"))) t->scrapeIntervalSec = tmp->val.i; - tr_dbg( "Torrent '%s' scrape successful." - " Rescraping in %d seconds", - t->name, t->scrapeIntervalSec ); + tr_ndbg( t->name, "Scrape successful. Rescraping in %d seconds.", + t->scrapeIntervalSec ); nextScrapeSec = t->scrapeIntervalSec; } diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index fc5ed0133..59e67508e 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -159,11 +159,27 @@ int tr_getMessageLevel( void ); typedef struct tr_msg_list { - uint8_t level; - time_t when; - char * message; - const char * file; - int line; + /* TR_MSG_ERR, TR_MSG_INF, or TR_MSG_DBG */ + uint8_t level; + + /* Time the message was generated */ + time_t when; + + /* The torrent associated with this message, + * or a module name such as "Port Forwarding" for non-torrent messages, + * or NULL. */ + char * name; + + /* The message */ + char * message; + + /* The source file where this message originated */ + const char * file; + + /* The line number in the source file where this message originated */ + int line; + + /* linked list of messages */ struct tr_msg_list * next; } tr_msg_list; diff --git a/libtransmission/upnp.c b/libtransmission/upnp.c index 05c9bc76a..174b07aa6 100644 --- a/libtransmission/upnp.c +++ b/libtransmission/upnp.c @@ -88,18 +88,18 @@ tr_upnpPulse( tr_upnp * handle, int port, int isEnabled ) errno = 0; devlist = upnpDiscover( 2000, NULL, NULL ); if( devlist == NULL ) { - tr_err( _( "%s: upnpDiscover failed (errno %d - %s)" ), getKey(), errno, tr_strerror(errno) ); + tr_nerr( getKey(), _( "upnpDiscover failed (errno %d - %s)" ), errno, tr_strerror(errno) ); } errno = 0; if( UPNP_GetValidIGD( devlist, &handle->urls, &handle->data, handle->lanaddr, sizeof(handle->lanaddr))) { - tr_inf( _( "%s: Found Internet Gateway Device \"%s\"" ), getKey(), handle->urls.controlURL ); - tr_inf( _( "%s: Local Address is \"%s\"" ), getKey(), handle->lanaddr ); + tr_ninf( getKey(), _( "Found Internet Gateway Device \"%s\"" ), handle->urls.controlURL ); + tr_ninf( getKey(), _( "Local Address is \"%s\"" ), handle->lanaddr ); handle->state = TR_UPNP_IDLE; handle->hasDiscovered = 1; } else { handle->state = TR_UPNP_ERR; - tr_err( _( "%s: UPNP_GetValidIGD failed (errno %d - %s)" ), getKey(), errno, tr_strerror(errno) ); - tr_err( _( "%s: If your router supports UPnP, please make sure UPnP is enabled!" ), getKey() ); + tr_nerr( getKey(), _( "UPNP_GetValidIGD failed (errno %d - %s)" ), errno, tr_strerror(errno) ); + tr_nerr( getKey(), _( "If your router supports UPnP, please make sure UPnP is enabled!" ) ); } freeUPNPDevlist( devlist ); } @@ -117,8 +117,8 @@ tr_upnpPulse( tr_upnp * handle, int port, int isEnabled ) UPNP_DeletePortMapping( handle->urls.controlURL, handle->data.servicetype, portStr, "TCP" ); - tr_dbg( _( "%s: Stopping port forwarding of \"%s\", service \"%s\"" ), - getKey(), handle->urls.controlURL, handle->data.servicetype ); + tr_ndbg( getKey(), _( "Stopping port forwarding of \"%s\", service \"%s\"" ), + handle->urls.controlURL, handle->data.servicetype ); handle->isMapped = 0; handle->state = TR_UPNP_IDLE; handle->port = -1; @@ -146,15 +146,15 @@ tr_upnpPulse( tr_upnp * handle, int port, int isEnabled ) "Transmission", "TCP" ); handle->isMapped = !err; } - tr_inf( _( "%s: Port forwarding via \"%s\", service \"%s\". (local address: %s:%d)" ), - getKey(), handle->urls.controlURL, handle->data.servicetype, handle->lanaddr, port ); + tr_ninf( getKey(), _( "Port forwarding via \"%s\", service \"%s\". (local address: %s:%d)" ), + handle->urls.controlURL, handle->data.servicetype, handle->lanaddr, port ); if( handle->isMapped ) { - tr_inf( _( "%s: Port forwarding successful!" ), getKey() ); + tr_ninf( getKey(), _( "Port forwarding successful!" ) ); handle->port = port; handle->state = TR_UPNP_IDLE; } else { - tr_err( _( "%s: Port forwarding failed with error %d (%d - %s)" ), getKey(), err, errno, tr_strerror(errno) ); - tr_err( _( "%s: If your router supports UPnP, please make sure UPnP is enabled!" ), getKey() ); + tr_nerr( getKey(), _( "Port forwarding failed with error %d (%d - %s)" ), err, errno, tr_strerror(errno) ); + tr_nerr( getKey(), _( "If your router supports UPnP, please make sure UPnP is enabled!" ) ); handle->port = -1; handle->state = TR_UPNP_ERR; } diff --git a/libtransmission/utils.c b/libtransmission/utils.c index bbd637162..f336f0771 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -116,7 +116,8 @@ tr_setMessageLevel( int level ) tr_lockUnlock( messageLock ); } -int tr_getMessageLevel( void ) +int +tr_getMessageLevel( void ) { int ret; @@ -128,7 +129,8 @@ int tr_getMessageLevel( void ) return ret; } -void tr_setMessageQueuing( int enabled ) +void +tr_setMessageQueuing( int enabled ) { tr_msgInit(); tr_lockLock( messageLock ); @@ -136,7 +138,8 @@ void tr_setMessageQueuing( int enabled ) tr_lockUnlock( messageLock ); } -tr_msg_list * tr_getQueuedMessages( void ) +tr_msg_list * +tr_getQueuedMessages( void ) { tr_msg_list * ret; @@ -150,7 +153,8 @@ tr_msg_list * tr_getQueuedMessages( void ) return ret; } -void tr_freeMessageList( tr_msg_list * list ) +void +tr_freeMessageList( tr_msg_list * list ) { tr_msg_list * next; @@ -158,6 +162,7 @@ void tr_freeMessageList( tr_msg_list * list ) { next = list->next; free( list->message ); + free( list->name ); free( list ); list = next; } @@ -192,7 +197,9 @@ tr_asprintf( char **strp, const char *fmt, ...) } void -tr_msg( const char * file, int line, int level, const char * fmt, ... ) +tr_msg( const char * file, int line, int level, + const char * name, + const char * fmt, ... ) { FILE * fp; @@ -229,6 +236,7 @@ tr_msg( const char * file, int line, int level, const char * fmt, ... ) newmsg->message = text; newmsg->file = file; newmsg->line = line; + newmsg->name = tr_strdup( name ); *messageQueueTail = newmsg; messageQueueTail = &newmsg->next; diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 30a29b23c..fc28982bf 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -43,10 +43,18 @@ void tr_msgInit( void ); #endif #endif -#define tr_err( a... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, ## a ) -#define tr_inf( a... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, ## a ) -#define tr_dbg( a... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, ## a ) -void tr_msg ( const char * file, int line, int level, const char * msg, ... ); +#define tr_nerr( n, a... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, n, ## a ) +#define tr_ninf( n, a... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, n, ## a ) +#define tr_ndbg( n, a... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, n, ## a ) + +#define tr_torerr( tor, a... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, tor->info.name, ## a ) +#define tr_torinf( tor, a... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, tor->info.name, ## a ) +#define tr_tordbg( tor, a... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, tor->info.name, ## a ) + +#define tr_err( a... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, NULL, ## a ) +#define tr_inf( a... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, NULL, ## a ) +#define tr_dbg( a... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, NULL, ## a ) +void tr_msg ( const char * file, int line, int level, const char * torrent, const char * msg, ... ); FILE* tr_getLog( void ); char* tr_getLogTimeStr( char * buf, int buflen ); diff --git a/libtransmission/verify.c b/libtransmission/verify.c index 939e8ccda..1f74aad90 100644 --- a/libtransmission/verify.c +++ b/libtransmission/verify.c @@ -125,7 +125,7 @@ verifyThreadFunc( void * unused UNUSED ) tor->verifyState = TR_VERIFY_NOW; - tr_inf( _( "Verifying torrent \"%s\"" ), tor->info.name ); + tr_torinf( tor, _( "Verifying torrent" ) ); for( i=0; iinfo.fileCount && !stopCurrent; ++i ) checkFile( tor, i, &stopCurrent ); @@ -157,7 +157,7 @@ tr_verifyAdd( tr_torrent * tor, { struct verify_node * node; - tr_inf( _( "Queueing \"%s\" for verification" ), tor->info.name ); + tr_torinf( tor, _( "Queued for verification" ) ); node = tr_new( struct verify_node, 1 ); node->torrent = tor;