IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

Improvements to logging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.