IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 25, 2007, 4:41:15 PM (19 years ago)
Author:
Paul Price
Message:

Adding facility for specifying trace destinations. Log and trace can now be directed to files on the command-line.

File:
1 edited

Legend:

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

    r15364 r15385  
    3737#define PS_DEFAULT_SITE ".ipprc"  // Default site config file
    3838
     39#define DEFAULT_LOG STDERR_FILENO       // Default file descriptor for log messages
     40#define DEFAULT_TRACE STDERR_FILENO     // Default file descriptor for trace messages
     41
    3942static bool readCameraConfig = true;    // Read the camera config on startup (with pmConfigRead)?
    4043static psArray *configPath = NULL;      // Search path for configuration files
     
    5962    psFree(config->arguments);
    6063    psFree(config->database);
     64
     65    // Close log and trace files
     66    if (config->logFD != STDOUT_FILENO && config->logFD != STDERR_FILENO) {
     67        close(config->logFD);
     68    }
     69    if (config->traceFD != STDOUT_FILENO && config->traceFD != STDERR_FILENO) {
     70        close(config->traceFD);
     71    }
     72
     73    return;
    6174}
    6275
     
    7992    config->defaultRecipe = NULL;
    8093
     94    config->traceFD = DEFAULT_TRACE;
     95    config->logFD = DEFAULT_LOG;
     96
    8197    // the file structure is used to carry pmFPAfiles
    8298    config->files = psMetadataAlloc ();
     
    124140}
    125141
     142
    126143void pmConfigSet(const char *path)
    127144{
     
    144161    psFree(configPath);
    145162    configPath = NULL;
     163
     164    return;
    146165}
    147166
     
    379398        psArgumentRemove(argNum, argc, argv);
    380399        if (argNum >= *argc) {
    381             psLogMsg("psModules.config", PS_LOG_WARN,
    382                      "-site command-line switch provided without the required filename --- ignored.\n");
     400            psWarning("-site command-line switch provided without the required filename --- ignored.\n");
    383401        } else {
    384402            siteName = psStringCopy(argv[argNum]);
     
    446464
    447465        argNum = psArgumentGet(*argc, argv, "-log");
    448         if (argNum > 0)
    449         {
     466        if (argNum > 0) {
    450467            psArgumentRemove(argNum, argc, argv);
    451468            if (argNum >= *argc) {
    452                 psLogMsg("psModules.config", PS_LOG_WARN, "-log command-line switch provided without the "
    453                          "required log destination --- ignored.\n");
     469                psWarning("-log command-line switch provided without the required log destination "
     470                          "--- ignored.\n");
    454471            } else {
    455                 if (!psLogSetDestination(psMessageDestination(argv[argNum]))) {
    456                     psLogMsg("psModules.config", PS_LOG_WARN, "Unable to set log destination to %s\n",
    457                              argv[argNum]);
    458                 }
     472                config->logFD = psMessageDestination(argv[argNum]);
    459473                psArgumentRemove(argNum, argc, argv);
    460474            }
    461         } else
    462         {
     475        } else {
    463476            // Set logging destination
    464477            psString logDest = psMetadataLookupStr(&mdok, config->site, "LOGDEST");
    465478            if (mdok && logDest && strlen(logDest) > 0) {
    466                 // XXX: Only stdout and stderr are provided for now; this section should be
    467                 // expanded in the future to do files, and perhaps even sockets.
    468                 if (!psLogSetDestination(psMessageDestination(logDest))) {
    469                     psLogMsg("psModules.config", PS_LOG_WARN, "Unable to set log destination to %s\n",
    470                              argv[argNum]);
    471                 }
    472             }
     479                config->logFD = psMessageDestination(logDest);
     480            }
     481        }
     482        if (!psLogSetDestination(config->logFD)) {
     483            psWarning("Unable to set log destination to file number %d --- ignored", config->logFD);
    473484        }
    474485
    475486        // Set trace levels
    476487        psMetadata *trace = psMetadataLookupMetadata(&mdok, config->site, "TRACE");
    477         if (mdok && trace)
    478         {
     488        if (mdok && trace) {
    479489            psMetadataIterator *traceIter = psMetadataIteratorAlloc(trace, PS_LIST_HEAD, NULL); // Iterator
    480490            psMetadataItem *traceItem = NULL; // Item from MD iteration
    481491            while ((traceItem = psMetadataGetAndIncrement(traceIter))) {
    482492                if (traceItem->type != PS_DATA_S32) {
    483                     psLogMsg("psModules.config", PS_LOG_WARN,
    484                              "The level for trace component %s is not of type S32 (%x)\n",
     493                    psWarning("The level for trace component %s is not of type S32 (%x)\n",
    485494                             traceItem->name, traceItem->type);
    486495                    continue;
    487496                }
    488                 psTrace("psModules.config", 7, "Setting trace level for %s to %d\n", traceItem->name, traceItem->data.S32);
     497                psTrace("psModules.config", 7, "Setting trace level for %s to %d\n",
     498                        traceItem->name, traceItem->data.S32);
    489499                (void)psTraceSetLevel(traceItem->name, traceItem->data.S32);
    490500            }
     
    494504        // Set trace formats
    495505        psString traceFormat = psMetadataLookupStr(&mdok, config->site, "TRACEFORMAT");
    496         if (mdok && traceFormat)
    497         {
     506        if (mdok && traceFormat) {
    498507            psTrace("psModules.config", 7, "Setting trace format to %s\n", traceFormat);
    499508            (void)psTraceSetFormat(traceFormat);
     
    502511        // Set trace destinations
    503512        #ifndef PS_NO_TRACE
    504         psString traceDest = psMetadataLookupStr(&mdok, config->site, "TRACEDEST");
    505         if (mdok && traceDest && strlen(traceDest) > 0)
    506         {
    507             psTrace("psModules.config", 7, "Setting trace destination to %s\n", traceDest);
    508             // XXX: Only stdout and stderr are provided for now; this section should be
    509             // expanded in the future to do files, and perhaps even sockets.
    510             if (!psTraceSetDestination(psMessageDestination(traceDest))) {
    511                 psLogMsg("psModules.config", PS_LOG_WARN, "Unable to set trace destination to %s\n", traceDest);
    512 
    513             }
     513        argNum = psArgumentGet(*argc, argv, "-tracedest");
     514        if (argNum > 0) {
     515            psArgumentRemove(argNum, argc, argv);
     516            if (argNum >= *argc) {
     517                psWarning("-tracedest command-line switch provided without the required trace destination "
     518                          "--- ignored.\n");
     519            } else {
     520                config->traceFD = psMessageDestination(argv[argNum]);
     521                psArgumentRemove(argNum, argc, argv);
     522            }
     523        } else {
     524            psString traceDest = psMetadataLookupStr(&mdok, config->site, "TRACEDEST");
     525            if (mdok && traceDest && strlen(traceDest) > 0) {
     526                psTrace("psModules.config", 7, "Setting trace destination to %s\n", traceDest);
     527                config->traceFD = psMessageDestination(traceDest);
     528            }
     529        }
     530        if (!psTraceSetDestination(config->traceFD)) {
     531            psWarning("Unable to set log destination to file %d\n", config->traceFD);
    514532        }
    515533        #endif
     
    741759        psArgumentRemove(argNum, argc, argv);
    742760        if (argNum >= *argc) {
    743             psLogMsg("psModules.config", PS_LOG_WARN,
    744                      "-dbserver command-line switch provided without the required server name --- ");
     761            psWarning("-dbserver command-line switch provided without the required server name --- ");
    745762        } else {
    746763            char *dbserver = argv[argNum]; // The camera configuration file to read
    747764            if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, NULL, dbserver)) {
    748                 psLogMsg("psModules.config", PS_LOG_WARN,
    749                          "failed to overwrite .ipprc DBSERVER value --- ");
     765                psWarning("Failed to overwrite .ipprc DBSERVER value");
    750766            }
    751767
     
    758774        psArgumentRemove(argNum, argc, argv);
    759775        if (argNum >= *argc) {
    760             psLogMsg("psModules.config", PS_LOG_WARN,
    761                      "-dbname command-line switch provided without the required database name --- ");
     776            psWarning("-dbname command-line switch provided without the required database name");
    762777        } else {
    763778            char *dbname = argv[argNum]; // The camera configuration file to read
    764779            if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
    765                 psLogMsg("psModules.config", PS_LOG_WARN,
    766                          "failed to overwrite .ipprc DBNAME value --- ");
     780                psWarning("Failed to overwrite .ipprc DBNAME value");
    767781            }
    768782
     
    775789        psArgumentRemove(argNum, argc, argv);
    776790        if (argNum >= *argc) {
    777             psLogMsg("psModules.config", PS_LOG_WARN,
    778                      "-dbuser command-line switch provided without the required database name --- ");
     791            psWarning("-dbuser command-line switch provided without the required database name");
    779792        } else {
    780793            char *dbuser = argv[argNum]; // The camera configuration file to read
    781794            if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
    782                 psLogMsg("psModules.config", PS_LOG_WARN,
    783                          "failed to overwrite .ipprc DBUSER value --- ");
     795                psWarning("Failed to overwrite .ipprc DBUSER value");
    784796            }
    785797
     
    792804        psArgumentRemove(argNum, argc, argv);
    793805        if (argNum >= *argc) {
    794             psLogMsg("psModules.config", PS_LOG_WARN,
    795                      "-dbpassword command-line switch provided without the required password --- ");
     806            psWarning("-dbpassword command-line switch provided without the required password");
    796807        } else {
    797808            char *dbpassword = argv[argNum]; // The camera configuration file to read
    798             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE, NULL, dbpassword)) {
    799                 psLogMsg("psModules.config", PS_LOG_WARN,
    800                          "failed to overwrite .ipprc DBPASSWORD value --- ");
     809            if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
     810                                  NULL, dbpassword)) {
     811                psWarning("Failed to overwrite .ipprc DBPASSWORD value");
    801812            }
    802813
     
    809820        psArgumentRemove(argNum, argc, argv);
    810821        if (argNum >= *argc) {
    811             psLogMsg("psModules.config", PS_LOG_WARN,
    812                      "-dbpport command-line switch provided without the required port number --- ");
     822            psWarning("-dbpport command-line switch provided without the required port number");
    813823        } else {
    814824            char *dbport = argv[argNum]; // The camera configuration file to read
    815             if (!psMetadataAddS32(config->site, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL, (psS32)atoi(dbport))) {
    816                 psLogMsg("psModules.config", PS_LOG_WARN,
    817                          "failed to overwrite .ipprc DBPORT value --- ");
     825            if (!psMetadataAddS32(config->site, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
     826                                  (psS32)atoi(dbport))) {
     827                psWarning("Failed to overwrite .ipprc DBPORT value");
    818828            }
    819829
     
    963973                result = true;
    964974            } else {
    965                 psLogMsg("psModules.config", PS_LOG_WARN,
    966                          "Camera %s, format %s also matches header --- ignored.\n",
     975                psWarning("Camera %s, format %s also matches header --- ignored.\n",
    967976                         cameraName, formatsItem->name);
    968977            }
     
    10871096
    10881097    if (!pmConfigFileRead(&camera, cameraPath, cameraName)) {
    1089         psLogMsg("psModules.config", PS_LOG_WARN, "Trouble reading reading camera configuration %s", cameraName);
     1098        psWarning("Trouble reading reading camera configuration %s", cameraName);
    10901099        psFree(camera);
    10911100        return NULL;
     
    11241133    }
    11251134    if (!(mdStatus01 && mdStatus02 && mdStatus03 && mdStatus04)) {
    1126         psLogMsg("psModules.config", PS_LOG_WARN,
    1127                  "Could not determine database server, name, user, and password from site metadata.\n");
     1135        psWarning("Could not determine database server, name, user, and password from site metadata.\n");
    11281136        return NULL;
    11291137    }
Note: See TracChangeset for help on using the changeset viewer.