Changeset 31036 for trunk/ippToPsps/src/Logger.c
- Timestamp:
- Mar 24, 2011, 1:21:35 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/src/Logger.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/src/Logger.c
r31032 r31036 40 40 static void print(void* this, const int8_t typeInt, const char* class, const char* fmt, ...) { 41 41 42 Logger* logger = (Logger*)this; 43 42 44 va_list args; 43 45 va_start(args, fmt); … … 55 57 break; 56 58 case MSG_DEBUG: 59 if (!logger->showDebug) return; 57 60 sprintf(typeStr, "DEBUG"); 58 61 break; … … 70 73 sprintf(msg_fmt, "%s", fmt); 71 74 else 72 sprintf(msg_fmt, "%1 9s | %6s | %15s | %s ", timeStr, typeStr, class, fmt);75 sprintf(msg_fmt, "%18s | %6s | %15s | %s ", timeStr, typeStr, class, fmt); 73 76 74 Logger* logger = (Logger*)this;75 77 76 78 // write either to file or stdout … … 83 85 84 86 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 85 90 */ 86 Logger* new_Logger(const char* path) { 87 91 Logger* new_Logger(const char* path, const int8_t showDebug) { 88 92 89 93 Logger* this = (Logger*)calloc(1, sizeof(Logger)); 90 94 91 95 this->file = NULL; 96 this->showDebug = showDebug; 92 97 gettimeofday(&this->startTime, 0); 93 98 94 99 // 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+"); 101 101 102 102 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 } 103 112 104 113 // method pointers
Note:
See TracChangeset
for help on using the changeset viewer.
