Changeset 31032 for trunk/ippToPsps/src/Logger.c
- Timestamp:
- Mar 24, 2011, 11:03:05 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/src/Logger.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/src/Logger.c
r31030 r31032 13 13 #include <stdarg.h> 14 14 #include <time.h> 15 #include <sys/time.h> 15 16 16 17 #include "Logger.h" … … 21 22 static void destroy(Logger* this) { 22 23 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"); 24 34 free(this); 25 35 } … … 28 38 Prints a message 29 39 */ 30 static void print(void* this, const int8_t typeInt, const char* fmt, ...) {40 static void print(void* this, const int8_t typeInt, const char* class, const char* fmt, ...) { 31 41 32 42 va_list args; … … 39 49 40 50 case MSG_INFO: 41 sprintf(typeStr, "INFO ");51 sprintf(typeStr, "INFO"); 42 52 break; 43 53 case MSG_ERROR: … … 60 70 sprintf(msg_fmt, "%s", fmt); 61 71 else 62 sprintf(msg_fmt, "% s | %s | %s", timeStr, typeStr,fmt);72 sprintf(msg_fmt, "%19s | %6s | %15s | %s ", timeStr, typeStr, class, fmt); 63 73 64 74 Logger* logger = (Logger*)this; … … 76 86 Logger* new_Logger(const char* path) { 77 87 88 78 89 Logger* this = (Logger*)calloc(1, sizeof(Logger)); 79 90 80 91 this->file = NULL; 92 gettimeofday(&this->startTime, 0); 81 93 82 94 // open a file to write to … … 85 97 this->file = fopen(path, "w+"); 86 98 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); 88 100 } 89 101 90 print(this, MSG_DEBUG, "Logger :Constructor\n");102 print(this, MSG_DEBUG, "Logger", "Constructor\n"); 91 103 92 104 // method pointers
Note:
See TracChangeset
for help on using the changeset viewer.
