IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 23, 2011, 4:27:17 PM (15 years ago)
Author:
rhenders
Message:

Introduced new logging system in order to provide proper audit trail

File:
1 edited

Legend:

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

    r31016 r31030  
    2626    if (!strncmp(typename, "TSTRING", 7)) return TSTRING;
    2727
    28     psError(PS_ERR_IO, false, "* Fits: Don't understand data type '%s'", typename);
     28//    this->logger->print(this->logger, MSG_ERROR, "Fits: Don't understand data type '%s'", typename);
    2929
    3030    return 0;
     
    3636static void destroy(Fits* this) {
    3737
     38    this->logger->print(this->logger, MSG_DEBUG, "Fits: Destructor\n");
     39
    3840    int status = 0;
    3941    if (fits_close_file(this->file, &status)) {
    4042
    41         psError(PS_ERR_IO, false, "* Fits: Unable to close FITS file");
     43        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to close FITS file '%s'\n", this->path);
    4244        fits_report_error(stderr, status);
    4345    }
    4446    else
    45         psLogMsg("ippToPsps", PS_LOG_INFO, "* Fits: Closed '%s'", this->path);
     47        this->logger->print(this->logger, MSG_INFO, "Fits: Closed FITS file '%s'\n", this->path);
     48
     49    free(this);
    4650}
    4751
     
    5660    if (status) {
    5761
    58         psError(PS_ERR_IO, false, "* Fits: Could not get value for header key '%s'\n", name);
     62        this->logger->print(this->logger, MSG_ERROR, "Fits: Could not get value for header key '%s' from file at '%s'\n", name, this->path);
    5963        return false;
    6064    }
     
    8286    if (status) {
    8387
    84         psError(PS_ERR_IO, false, "* Fits: Failed to read vector column %d row %ld", col, row);
     88        this->logger->print(this->logger, MSG_ERROR, "Fits: Failed to read vector column %d row %ld\n", col, row);
    8589        return false;
    8690    }
     
    98102    if (status) {
    99103
    100         psError(PS_ERR_IO, false, "* Fits: Could not get column number for '%s'\n", name);
     104        this->logger->print(this->logger, MSG_ERROR, "Fits: Could not get column number for '%s'\n", name);
    101105        return false;
    102106    }
     
    119123    if (status) {
    120124
    121         psError(PS_ERR_IO, false, "* Fits: Unable to read col '%s'", name);
     125        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to read col '%s'\n", name);
    122126        return false;
    123127    }
     
    127131    if (status) {
    128132
    129         psError(PS_ERR_IO, false, "* Fits: Unable to read type info for '%s'", name);
     133        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to read type info for '%s'\n", name);
    130134        return false;
    131135    }
     
    143147    if (fits_movnam_hdu(this->file, type, name, 0, &status)) {
    144148
    145         psError(PS_ERR_IO, false, "* Fits: Can't move to table extension named '%s'\n", name);
     149        this->logger->print(this->logger, MSG_ERROR, "Fits: Can't move to table extension named '%s'\n", name);
     150        return false;
    146151    }
    147152
     
    173178    if (fits_get_num_rows(this->file, count, &status)) {
    174179
    175         psError(PS_ERR_IO, false, "* Fits: Count not count rows in this table\n");
     180        this->logger->print(this->logger, MSG_ERROR, "Fits: Count not count rows in this table\n");
    176181        return false;
    177182    }
     
    196201    if (remove(this->path) == -1) {
    197202
    198         psError(PS_ERR_UNKNOWN, false, "* Fits: Unable to delete '%s'", this->path);
    199         return false;
    200     }
     203        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to delete '%s'\n", this->path);
     204        return false;
     205    }
     206
     207    this->logger->print(this->logger, MSG_INFO, "Fits: Deleted FITS file at '%s'\n", this->path);
    201208
    202209    return true;
     
    228235    if (status) {
    229236
    230         psError(PS_ERR_IO, false, "* Fits: Unable to delet rows using rowlist \n");
     237        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to delete rows using rowlist\n");
    231238        return false;
    232239    }
     
    283290    else {
    284291
    285         psError(PS_ERR_IO, false, "* Fits: Don't support datatype '%d' yet\n", datatype);
    286         return false;
    287     }
    288 
    289     if (status) {
    290 
    291         psError(PS_ERR_IO, false, "* Fits: Unable to read column data from column %d\n", colnum);
     292        this->logger->print(this->logger, MSG_ERROR, "Fits: Don't understand datatype '%d'\n", datatype);
     293        return false;
     294    }
     295
     296    if (status) {
     297
     298        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to read column data from column %d\n", colnum);
    292299        return false;
    293300
     
    331338    if (status) {
    332339
    333         psError(PS_ERR_IO, false, "* Fits: Unable to write column data for column %d\n", colnum);
     340        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to write column data for column %d\n", colnum);
    334341        return false;
    335342
     
    355362    if (status) {
    356363
    357         psError(PS_ERR_IO,"* Fits: Unable to create table: '%s'", name);
     364        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to create table: '%s'\n", name);
    358365        return false;
    359366    }
     
    366373  Initilization common to all constructors
    367374  */
    368 static void init(Fits* this) {
     375static Fits* init(const char* path, Logger* logger) {
     376
     377    Fits* this = (Fits*)calloc(1, sizeof(Fits));
     378
     379    // fields
     380    strcpy(this->path, path);
     381    this->logger = logger;
    369382
    370383    // method pointers
     
    390403    assert(this);
    391404
     405    return this;
    392406}
    393407
     
    398412
    399413*/
    400 Fits* existing_Fits(char* path) {
    401 
    402     Fits* this = (Fits*)calloc(1, sizeof(Fits));
    403 
    404     int status = 0;
    405     strcpy(this->path, path);
    406 
    407     if (fits_open_file(&this->file, this->path, READONLY, &status)) {
    408 
    409         psError(PS_ERR_IO, false, "* Fits: Unable to open FITS file here %s\n", path);
     414Fits* existing_Fits(const char* path, Logger* logger) {
     415
     416    Fits* this = init(path, logger);
     417    this->logger->print(this->logger, MSG_DEBUG, "Fits: Constructor for existing file at '%s'\n", path);
     418
     419    int status = 0;
     420    if (fits_open_file(&this->file, path, READONLY, &status)) {
     421
     422        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to open FITS file here %s\n", path);
    410423        this->file = NULL;
    411424    }
    412425
    413     init(this);
    414426
    415427    return this;
     
    421433  Returns a new Fits object representing a new FITS file.
    422434  */
    423 Fits* new_Fits(char* path) {
    424 
    425     Fits* this = (Fits*)calloc(1, sizeof(Fits));
    426 
    427     int status = 0;
    428     strcpy(this->path, path);
    429 
    430     if (fits_create_file(&this->file, this->path, &status)) {
    431 
    432         psError(PS_ERR_IO, false, "* Fits: Unable to create file here '%s'", path);
     435Fits* new_Fits(const char* path, Logger* logger) {
     436
     437    Fits* this = init(path, logger);
     438    this->logger->print(this->logger, MSG_DEBUG, "Fits: Constructor for new file at '%s'\n", path);
     439
     440    int status = 0;
     441    if (fits_create_file(&this->file, path, &status)) {
     442
     443        this->logger->print(this->logger, MSG_ERROR, "Fits: Unable to create FITS file here '%s'\n", path);
    433444        this->file = NULL;
    434445    }
    435446
    436     init(this);
    437 
    438447    return this;
    439448}
Note: See TracChangeset for help on using the changeset viewer.