Changeset 10162
- Timestamp:
- Feb 11, 2010, 1:37:59 AM (12 years ago)
- Location:
- trunk/daemon
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/daemon.c
r10135 r10162 72 72 { 942, "no-incomplete-dir", "Don't store incomplete torrents in a different location", NULL, 0, NULL }, 73 73 { 'd', "dump-settings", "Dump the settings and exit", "d", 0, NULL }, 74 { 'e', "logfile", "Dump the log messages to this filename", "e", 1, "<filename>" }, 74 75 { 'f', "foreground", "Run in the foreground instead of daemonizing", "f", 0, NULL }, 75 76 { 'g', "config-dir", "Where to look for configuration files", "g", 1, "<path>" }, … … 229 230 230 231 static void 231 printMessage( tr_bool foreground, int level, const char * name, const char * message, const char * file, int line ) 232 { 233 #ifdef HAVE_SYSLOG 234 if( foreground ) 232 printMessage( FILE * logfile, int level, const char * name, const char * message, const char * file, int line ) 233 { 234 if( logfile != NULL ) 235 235 { 236 236 char timestr[64]; 237 237 tr_getLogTimeStr( timestr, sizeof( timestr ) ); 238 238 if( name ) 239 fprintf( stderr, "[%s] %s %s (%s:%d)\n", timestr, name, message, file, line );239 fprintf( logfile, "[%s] %s %s (%s:%d)\n", timestr, name, message, file, line ); 240 240 else 241 fprintf( stderr, "[%s] %s (%s:%d)\n", timestr, message, file, line ); 242 } 241 fprintf( logfile, "[%s] %s (%s:%d)\n", timestr, message, file, line ); 242 } 243 #ifdef HAVE_SYSLOG 243 244 else /* daemon... write to syslog */ 244 245 { … … 257 258 syslog( priority, "%s (%s:%d)", message, file, line ); 258 259 } 259 #else260 {261 char timestr[64];262 tr_getLogTimeStr( timestr, sizeof( timestr ) );263 if( name )264 fprintf( stderr, "[%s] %s %s (%s:%d)\n", timestr, name, message, file, line );265 else266 fprintf( stderr, "[%s] %s (%s:%d)\n", timestr, message, file, line );267 }268 260 #endif 269 261 } 270 262 271 263 static void 272 pumpLogMessages( tr_bool foreground)264 pumpLogMessages( FILE * logfile ) 273 265 { 274 266 const tr_msg_list * l; … … 276 268 277 269 for( l=list; l!=NULL; l=l->next ) 278 printMessage( foreground, l->level, l->name, l->message, l->file, l->line );270 printMessage( logfile, l->level, l->name, l->message, l->file, l->line ); 279 271 280 272 tr_freeMessageList( list ); … … 293 285 const char * configDir = NULL; 294 286 dtr_watchdir * watchdir = NULL; 287 FILE * logfile = NULL; 295 288 296 289 signal( SIGINT, gotsig ); … … 330 323 case 'd': dumpSettings = TRUE; 331 324 break; 325 case 'e': logfile = fopen( optarg, "a+" ); 326 if( logfile == NULL ) 327 fprintf( stderr, "Couldn't open \"%s\": %s\n", optarg, tr_strerror( errno ) ); 328 break; 332 329 case 'f': foreground = TRUE; 333 330 break; … … 394 391 } 395 392 393 if( foreground && !logfile ) 394 logfile = stderr; 395 396 396 if( !loaded ) 397 397 { 398 printMessage( foreground, TR_MSG_ERR, MY_NAME, "Error loading config file -- exiting.", __FILE__, __LINE__ );398 printMessage( logfile, TR_MSG_ERR, MY_NAME, "Error loading config file -- exiting.", __FILE__, __LINE__ ); 399 399 return -1; 400 400 } … … 412 412 char buf[256]; 413 413 tr_snprintf( buf, sizeof( buf ), "Failed to dameonize: %s", tr_strerror( errno ) ); 414 printMessage( foreground, TR_MSG_ERR, MY_NAME, buf, __FILE__, __LINE__ );414 printMessage( logfile, TR_MSG_ERR, MY_NAME, buf, __FILE__, __LINE__ ); 415 415 exit( 1 ); 416 416 } … … 458 458 tr_wait_msec( 1000 ); /* sleep one second */ 459 459 dtr_watchdir_update( watchdir ); 460 pumpLogMessages( foreground);460 pumpLogMessages( logfile ); 461 461 } 462 462 -
trunk/daemon/transmission-daemon.1
r10132 r10162 27 27 .Op Fl V 28 28 .Op Fl w Ar download-dir 29 .Op Fl e Ar logfile 29 30 .Ek 30 31 .Sh DESCRIPTION … … 115 116 .It Fl w Fl -download-dir 116 117 Where to store downloaded data. 118 .It Fl e Fl -logfile 119 Where to store transmission's log messages. 117 120 .El 118 121 .Sh ENVIRONMENT
Note: See TracChangeset
for help on using the changeset viewer.