Changeset 10162


Ignore:
Timestamp:
Feb 11, 2010, 1:37:59 AM (12 years ago)
Author:
charles
Message:

(trunk daemon) #2890 "Add option to specify logfile in transmission-daemon" -- implemented for 1.90

Location:
trunk/daemon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/daemon.c

    r10135 r10162  
    7272    { 942, "no-incomplete-dir", "Don't store incomplete torrents in a different location", NULL, 0, NULL },
    7373    { 'd', "dump-settings", "Dump the settings and exit", "d", 0, NULL },
     74    { 'e', "logfile", "Dump the log messages to this filename", "e", 1, "<filename>" },
    7475    { 'f', "foreground", "Run in the foreground instead of daemonizing", "f", 0, NULL },
    7576    { 'g', "config-dir", "Where to look for configuration files", "g", 1, "<path>" },
     
    229230
    230231static 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 )
     232printMessage( FILE * logfile, int level, const char * name, const char * message, const char * file, int line )
     233{
     234    if( logfile != NULL )
    235235    {
    236236        char timestr[64];
    237237        tr_getLogTimeStr( timestr, sizeof( timestr ) );
    238238        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 );
    240240        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
    243244    else /* daemon... write to syslog */
    244245    {
     
    257258            syslog( priority, "%s (%s:%d)", message, file, line );
    258259    }
    259 #else
    260     {
    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         else
    266             fprintf( stderr, "[%s] %s (%s:%d)\n", timestr, message, file, line );
    267     }
    268260#endif
    269261}
    270262
    271263static void
    272 pumpLogMessages( tr_bool foreground )
     264pumpLogMessages( FILE * logfile )
    273265{
    274266    const tr_msg_list * l;
     
    276268
    277269    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 );
    279271
    280272    tr_freeMessageList( list );
     
    293285    const char * configDir = NULL;
    294286    dtr_watchdir * watchdir = NULL;
     287    FILE * logfile = NULL;
    295288
    296289    signal( SIGINT, gotsig );
     
    330323            case 'd': dumpSettings = TRUE;
    331324                      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;
    332329            case 'f': foreground = TRUE;
    333330                      break;
     
    394391    }
    395392
     393    if( foreground && !logfile )
     394        logfile = stderr;
     395
    396396    if( !loaded )
    397397    {
    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__ );
    399399        return -1;
    400400    }
     
    412412        char buf[256];
    413413        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__ );
    415415        exit( 1 );
    416416    }
     
    458458        tr_wait_msec( 1000 ); /* sleep one second */
    459459        dtr_watchdir_update( watchdir );
    460         pumpLogMessages( foreground );
     460        pumpLogMessages( logfile );
    461461    }
    462462
  • trunk/daemon/transmission-daemon.1

    r10132 r10162  
    2727.Op Fl V
    2828.Op Fl w Ar download-dir
     29.Op Fl e Ar logfile
    2930.Ek
    3031.Sh DESCRIPTION
     
    115116.It Fl w Fl -download-dir
    116117Where to store downloaded data.
     118.It Fl e Fl -logfile
     119Where to store transmission's log messages.
    117120.El
    118121.Sh ENVIRONMENT
Note: See TracChangeset for help on using the changeset viewer.