IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31036


Ignore:
Timestamp:
Mar 24, 2011, 1:21:35 PM (15 years ago)
Author:
rhenders
Message:

Improvements to logging

Location:
trunk/ippToPsps/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/src/Batch.c

    r31033 r31036  
    113113    while (fgets(line, 1000, file) != NULL) this->numOfInputFiles++;
    114114
    115     this->logger->print(this->logger, MSG_INFO, "Batch", "%d input files found\n", this->numOfInputFiles);
     115    this->logger->print(this->logger, MSG_INFO, "Batch",
     116            "%d input file%s found\n", this->numOfInputFiles, (this->numOfInputFiles > 1) ? "s" : "");
    116117
    117118    if (this->numOfInputFiles < 1) return false;
     
    256257static void print(Batch* this) {
    257258
    258     printf("\n");
    259     printf("* surveyType      : '%s'\n", this->surveyType);
    260     printf("* surveyID        : %d\n", this->surveyID);
    261     printf("* resultsPath     : '%s'\n", this->resultsPath);
    262     printf("* numOfInputFiles : %d\n", this->numOfInputFiles);
    263     printf("* fitsInPath      : '%s'\n", this->fitsInPath);
     259    this->logger->print(this->logger, MSG_INFO, "Batch", "\n");
     260    this->logger->print(this->logger, MSG_INFO, "Batch", "     Class fields:\n");
     261    this->logger->print(this->logger, MSG_INFO, "Batch", "surveyType      : %s\n", this->surveyType);
     262    this->logger->print(this->logger, MSG_INFO, "Batch", "surveyID        : %d\n", this->surveyID);
     263    this->logger->print(this->logger, MSG_INFO, "Batch", "resultsPath     : %s\n", this->resultsPath);
     264    this->logger->print(this->logger, MSG_INFO, "Batch", "numOfInputFiles : %d\n", this->numOfInputFiles);
     265    this->logger->print(this->logger, MSG_INFO, "Batch", "fitsInPath      : %s\n", this->fitsInPath);
     266    this->logger->print(this->logger, MSG_INFO, "Batch", "testMode        : %s\n", this->testMode ? "yes" : "no");
    264267}
    265268
  • trunk/ippToPsps/src/Batch.h

    r31030 r31036  
    3030  - StackBatch
    3131
    32   All subclasses need to implement the run() method and may need to implenent print()
     32  All subclasses need to implement the run() method and may need to implement print()
    3333  */
    3434typedef struct Batch {
  • trunk/ippToPsps/src/DetectionBatch.c

    r31033 r31036  
    440440    this->base.print(&this->base);
    441441
    442     printf("* exp ID          : %d\n", this->expId);
    443     printf("* exp name        : '%s'\n",  this->expName ? this->expName : "undef");
    444     printf("\n");
     442    this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", "exp ID          : %d\n", this->expId);
     443    this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", "exp name        : %s\n",  this->expName ? this->expName : "undef");
     444    this->base.logger->print(this->base.logger, MSG_INFO, "DetectionBatch", "\n");
    445445}
    446446
     
    518518    parseArguments(this, *argc, argv);
    519519
     520    this->print(this);
     521
    520522    return this;
    521523}
     
    528530//    ippToPsps_VersionPrint();
    529531
    530     Logger* logger = new_Logger(NULL);
     532    Logger* logger = new_Logger(NULL, false);
     533//    Logger* logger = new_Logger("./detBatchLog.txt", false);
    531534    logger->print(logger, MSG_INFO, "main", "Creating new detection batch\n");
    532535
  • trunk/ippToPsps/src/Fits.c

    r31033 r31036  
    4545    }
    4646    else
    47         this->logger->print(this->logger, MSG_INFO, "Fits", "Closed FITS file '%s'\n", this->path);
     47        this->logger->print(this->logger, MSG_DEBUG, "Fits", "Closed FITS file '%s'\n", this->path);
    4848
    4949    free(this);
  • trunk/ippToPsps/src/InitBatch.c

    r31033 r31036  
    5050    }
    5151
    52 
    5352    return true;
    5453}
     
    7271    parseArguments(this, *argc, argv);
    7372
     73    this->print(this);
     74
    7475    return this;
    7576}
     
    8283//    ippToPsps_VersionPrint();
    8384
    84     Logger* logger = new_Logger(NULL);
     85    Logger* logger = new_Logger(NULL, false);
    8586    logger->print(logger, MSG_INFO, "main", "Creating new initialization batch\n");
    8687
     
    9091
    9192    initBatch->destroy(initBatch);
    92 
    9393
    9494    // tidy up
  • trunk/ippToPsps/src/Logger.c

    r31032 r31036  
    4040static void print(void* this, const int8_t typeInt, const char* class, const char* fmt, ...) {
    4141
     42    Logger* logger = (Logger*)this;
     43
    4244    va_list args;
    4345    va_start(args, fmt);
     
    5557            break;
    5658        case MSG_DEBUG:
     59            if (!logger->showDebug) return;
    5760            sprintf(typeStr, "DEBUG");
    5861            break;
     
    7073        sprintf(msg_fmt, "%s", fmt);
    7174    else
    72         sprintf(msg_fmt, "%19s | %6s | %15s | %s ", timeStr, typeStr, class,  fmt);
     75        sprintf(msg_fmt, "%18s | %6s | %15s | %s ", timeStr, typeStr, class,  fmt);
    7376
    74     Logger* logger = (Logger*)this;
    7577
    7678    // write either to file or stdout
     
    8385
    8486  Returns a new Logger object.
     87 
     88  path      - path to file where log should be saved, otherwise stdout is used
     89  showDebug - show debug messages or not
    8590  */
    86 Logger* new_Logger(const char* path) {
    87 
     91Logger* new_Logger(const char* path, const int8_t showDebug) {
    8892
    8993    Logger* this = (Logger*)calloc(1, sizeof(Logger));
    9094
    9195    this->file = NULL;
     96    this->showDebug = showDebug;
    9297    gettimeofday(&this->startTime, 0);
    9398
    9499    // open a file to write to
    95     if (path != NULL) {
    96 
    97         this->file = fopen(path, "w+");
    98         if (this->file == NULL)
    99             print(this, MSG_ERROR, "Logger", "Cannot open file for writing here '%s'\n", path);
    100     }
     100    if (path != NULL) this->file = fopen(path, "w+");
    101101
    102102    print(this, MSG_DEBUG, "Logger", "Constructor\n");
     103    print(this, MSG_INFO, "Logger", "Starting timer\n");
     104
     105    if (path != NULL) {
     106
     107        if (this->file == NULL)
     108            print(this, MSG_ERROR, "Logger", "Cannot open file for writing here '%s'\n", path);
     109        else
     110            printf("**** Saving log to '%s'\n", path);
     111    }
    103112
    104113    // method pointers
  • trunk/ippToPsps/src/Logger.h

    r31032 r31036  
    3232    FILE* file;
    3333    struct timeval startTime;
     34    int8_t showDebug;
    3435
    3536    // methods
     
    4344
    4445// constructor
    45 Logger* new_Logger(const char* path);
     46Logger* new_Logger(const char* path, const int8_t showDebug);
    4647
    4748# endif // IPPTOPSPS_LOGGER_H
  • trunk/ippToPsps/src/StackBatch.c

    r31033 r31036  
    386386    this->base.print(&this->base);
    387387
    388     printf("* skycell ID      : %d\n", this->skycellId);
    389     printf("\n");
     388    this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", "skycell ID      : %d\n", this->skycellId);
     389    this->base.logger->print(this->base.logger, MSG_INFO, "StackBatch", "\n");
    390390}
    391391
     
    454454    parseArguments(this, *argc, argv);
    455455
     456    this->print(this);
     457
    456458    return this;
    457459}
     
    464466//    ippToPsps_VersionPrint();
    465467
    466     int exitCode;
    467 
    468     Logger* logger = new_Logger(NULL);
     468    Logger* logger = new_Logger(NULL, false);
    469469    logger->print(logger, MSG_INFO, "main", "Creating new stack batch\n");
    470470
    471471    StackBatch* stackBatch = new_StackBatch(logger, &argc, argv);
    472472    stackBatch->base.run(stackBatch);
    473     exitCode = stackBatch->base.exitCode;
     473    int exitCode = stackBatch->base.exitCode;
    474474
    475475    stackBatch->destroy(stackBatch);
Note: See TracChangeset for help on using the changeset viewer.