/** * Create a new logfile. */ LogFile::LogFile(const char *inFilename) { assert(inFilename); filename=inFilename; instream = NULL; outputter = NULL; file = NULL; try { /* Try to open the logfile */ openLogfile(); /* If it's opened succesfully, read the next (first) line */ if(!nextLine()) { /* If nextLine didn't return a record, this entry is invalid. */ throw LogfileError("Error trying to read an initial record."); } else { outputter = LineOutputter::forLine(line); closeLogfile(); } } catch(LogfileError e) { if (file != NULL) { closeLogfile(); } delete outputter; throw; } }
/** * Get rid of a logfile that's no longer needed. */ LogFile::~LogFile() { if(instream != NULL) { closeLogfile(); } delete outputter; }
cSmileLogger::~cSmileLogger() { smileMutexLock(logmsgMtx); if (msg != NULL) free(msg); closeLogfile(); if (logfile != NULL) free(logfile); smileMutexUnlock(logmsgMtx); smileMutexDestroy(logmsgMtx); }
void appendToLogfile(const char* text) { word mjd; byte hour; byte min; byte sec; word year; byte month; byte day; byte weekday; char str[20]; //TAP_Print("Appending to log file...\r\n"); openLogfile(); if (logFD != NULL) { TAP_Hdd_Fseek(logFD, logByteCount, SEEK_SET); TAP_GetTime( &mjd, &hour, &min, &sec); TAP_ExtractMjd(mjd, &year, &month, &day, &weekday); sprintf(str,"%02d-%02d-%04d %02d:%02d:%02d - ", day, month, year, hour, min, sec); TAP_Hdd_Fwrite((void*)str, strlen(str), 1, logFD); TAP_Hdd_Fwrite((void*)text, strlen(text), 1, logFD); TAP_Hdd_Fwrite((void*)"\r\n", strlen("\r\n"), 1, logFD); logByteCount += strlen(str) + strlen(text) + strlen("\r\n"); closeLogfile(); } }