IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2011, 11:03:05 AM (15 years ago)
Author:
rhenders
Message:

Now incorporating timing code; added class name to args of print method

File:
1 edited

Legend:

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

    r31030 r31032  
    1313#include <stdarg.h>
    1414#include <time.h>
     15       #include <sys/time.h>
    1516
    1617#include "Logger.h"
     
    2122static void destroy(Logger* this) {
    2223
    23     this->print(this, MSG_DEBUG, "Logger: Destructor\n");
     24    struct timeval stopTime;
     25    gettimeofday(&stopTime, 0);
     26    double secs = (double)(stopTime.tv_sec-this->startTime.tv_sec);
     27
     28    this->print(this, MSG_INFO, "Logger",
     29            "Completed in %.1f %s\n",
     30            (secs<60.0) ? secs : (secs/60.0),
     31            (secs<60.0) ? "sec(s)" : "min(s)");
     32
     33    this->print(this, MSG_DEBUG, "Logger", "Destructor\n");
    2434    free(this);
    2535}
     
    2838  Prints a message
    2939  */
    30 static void print(void* this, const int8_t typeInt, const char* fmt, ...) {
     40static void print(void* this, const int8_t typeInt, const char* class, const char* fmt, ...) {
    3141
    3242    va_list args;
     
    3949
    4050        case MSG_INFO:
    41             sprintf(typeStr, "INFO ");
     51            sprintf(typeStr, "INFO");
    4252            break;
    4353        case MSG_ERROR:
     
    6070        sprintf(msg_fmt, "%s", fmt);
    6171    else
    62         sprintf(msg_fmt, "%s | %s | %s", timeStr, typeStr, fmt);
     72        sprintf(msg_fmt, "%19s | %6s | %15s | %s ", timeStr, typeStr, class, fmt);
    6373
    6474    Logger* logger = (Logger*)this;
     
    7686Logger* new_Logger(const char* path) {
    7787
     88
    7889    Logger* this = (Logger*)calloc(1, sizeof(Logger));
    7990
    8091    this->file = NULL;
     92    gettimeofday(&this->startTime, 0);
    8193
    8294    // open a file to write to
     
    8597        this->file = fopen(path, "w+");
    8698        if (this->file == NULL)
    87             print(this, MSG_ERROR, "Logger: cannot open file for writing here '%s'\n", path);
     99            print(this, MSG_ERROR, "Logger", "Cannot open file for writing here '%s'\n", path);
    88100    }
    89101
    90     print(this, MSG_DEBUG, "Logger: Constructor\n");
     102    print(this, MSG_DEBUG, "Logger", "Constructor\n");
    91103
    92104    // method pointers
Note: See TracChangeset for help on using the changeset viewer.