IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16339


Ignore:
Timestamp:
Feb 6, 2008, 11:00:43 AM (18 years ago)
Author:
Paul Price
Message:

Updating trace and log destinations to take path:// and neb:// URIs.
Looks like Gene already did this, but I've removed protocols from
psMessageDestination, and I think this is a little cleaner.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfig.c

    r16231 r16339  
    463463        }
    464464
    465         // set the log file from the config files or -log argument
    466         psString logDest = NULL;
     465        // Set logging destination first from command line, second from site configuration
     466        psString logDest = NULL;        // Logging destination
    467467        argNum = psArgumentGet(*argc, argv, "-log");
    468468        if (argNum > 0) {
     
    470470            if (argNum >= *argc) {
    471471                psWarning("-log command-line switch provided without the required log destination "
    472                           "--- ignored.\n");
     472                          "--- ignored.");
    473473            } else {
    474                 logDest = pmConfigConvertFilename (argv[argNum], config, true);
    475                 psArgumentRemove(argNum, argc, argv);
    476             }
    477         } else {
    478             // Set logging destination
    479             psString tmpName = psMetadataLookupStr(&mdok, config->site, "LOGDEST");
    480             if (mdok && tmpName && strlen(tmpName) > 0) {
    481                 logDest = pmConfigConvertFilename (tmpName, config, true);
    482             }
    483         }
    484         if (logDest) {
    485             if (strcasecmp (logDest, "stdout") && strcasecmp (logDest, "stderr")) {
    486                 // psMessageDestination takes a target of the form file:location
    487                 // XXX should we modify psMessageDestination to recognize a plain file?
    488                 psStringPrepend (&logDest, "file:");
    489             }
    490             config->logFD = psMessageDestination(logDest);
    491         }
     474                logDest = psStringCopy(argv[argNum]);
     475                psArgumentRemove(argNum, argc, argv);
     476            }
     477        }
     478        if (!logDest) {
     479            logDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->site, "LOGDEST"));
     480        }
     481        if (logDest) {
     482            psString resolved = pmConfigConvertFilename(logDest, config, true); // Resolved filename
     483            if (!resolved || strlen(resolved) == 0) {
     484                psWarning("Unable to resolve log destination: %s --- ignored", logDest);
     485            } else {
     486                config->logFD = psMessageDestination(resolved);
     487            }
     488            psFree(resolved);
     489            psFree(logDest);
     490        }
    492491        if (!psLogSetDestination(config->logFD)) {
    493             psWarning("Unable to set log destination to file number %d (%s) --- ignored", config->logFD, logDest);
    494             // XXX make this a fatal error?
    495         }
    496         psFree (logDest);
     492            psError(PS_ERR_IO, false, "Unable to set log destination to file number %d --- ignored",
     493                    config->logFD);
     494            psFree(config);
     495            return NULL;
     496        }
    497497
    498498        // Set trace levels
     
    522522
    523523        // Set trace destinations
    524         psString traceDest = NULL;
     524        psString traceDest = NULL;      // Trace destination
    525525        argNum = psArgumentGet(*argc, argv, "-tracedest");
    526526        if (argNum > 0) {
     
    530530                          "--- ignored.\n");
    531531            } else {
    532                 traceDest = pmConfigConvertFilename (argv[argNum], config, true);
     532                traceDest = psStringCopy(argv[argNum]);
    533533                psArgumentRemove(argNum, argc, argv);
    534534            }
    535         } else {
    536             psString tmpName = psMetadataLookupStr(&mdok, config->site, "TRACEDEST");
    537             if (mdok && tmpName && strlen(tmpName) > 0) {
    538                 traceDest = pmConfigConvertFilename (tmpName, config, true);
    539                 psTrace("psModules.config", 7, "Setting trace destination to %s\n", traceDest);
    540             }
    541         }
    542         if (traceDest) {
    543             if (strcasecmp (traceDest, "stdout") && strcasecmp (traceDest, "stderr")) {
    544                 // psMessageDestination takes a target of the form file:location
    545                 // XXX should we modify psMessageDestination to recognize a plain file?
    546                 psStringPrepend (&traceDest, "file:");
    547             }
    548             config->traceFD = psMessageDestination(traceDest);
    549         }
    550         if (!psTraceSetDestination(config->traceFD)) {
    551             psWarning("Unable to set trace destination to file number %d (%s)\n", config->traceFD, traceDest);
    552         }
    553         psFree (traceDest);
     535        }
     536        if (!traceDest) {
     537            traceDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->site, "TRACEDEST"));
     538        }
     539        if (traceDest) {
     540            psString resolved = pmConfigConvertFilename(traceDest, config, true); // Resolved filename
     541            if (!resolved || strlen(resolved) == 0) {
     542                psWarning("Unable to resolve trace destination: %s --- ignored", traceDest);
     543            } else {
     544                config->traceFD = psMessageDestination(resolved);
     545            }
     546            psFree(resolved);
     547            psFree(traceDest);
     548        }
     549        if (!psLogSetDestination(config->traceFD)) {
     550            psError(PS_ERR_IO, false, "Unable to set trace destination to file number %d --- ignored",
     551                    config->traceFD);
     552            psFree(config);
     553            return NULL;
     554        }
    554555
    555556        // Allow command line options to override defaults for logging.
     
    10601061                }
    10611062            } else {
    1062               // XXX have to be careful with this construction: it catches other errors cluttering up the stack...
     1063              // XXX have to be careful with this construction: it catches other errors cluttering up the stack...
    10631064                psErr *error = psErrorLast();
    10641065                if (error->code != PS_ERR_NONE) {
Note: See TracChangeset for help on using the changeset viewer.