diff --git a/printx.c b/printx.c index b3488f7..e57e15a 100644 --- a/printx.c +++ b/printx.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "printx.h" #include "ui.h" @@ -13,8 +13,8 @@ FILE* logfiles[5] = {NULL, NULL, NULL, NULL, NULL}; char s_color[4][12] = {"\x1b[01;31m", "\x1b[01;33m", "\x1b[01;32m", "\x1b[01;36m"}; -char f_name[5][5] = {"MAIN", "UI ", "NFC ", "HVC ", "BUS "}; -float start; +char f_name[6][5] = {"MAIN", "UI ", "NFC ", "HVC ", "BUS ", "TEMP"}; +struct timeval tv; void removeCharFromString(char c, char *str) { @@ -27,29 +27,28 @@ void removeCharFromString(char c, char *str) bool initLog() { - char filename[FILENAME_LENGTH]; - time_t now = time(NULL); + //char filename[FILENAME_LENGTH]; + //time_t now = time(NULL); - strftime(filename, FILENAME_LENGTH, "%F-%T:%d", localtime(&now)); - setStartTime(filename); - strftime(filename, FILENAME_LENGTH, "log/%F-%T:%d", localtime(&now)); - strcat(filename, ".log"); + //strftime(filename, FILENAME_LENGTH, "%F-%T:%d", localtime(&now)); + //setStartTime(filename); + //strftime(filename, FILENAME_LENGTH, "log/%F-%T:%d", localtime(&now)); + //strcat(filename, ".log"); - logfile = fopen(filename, "w"); - if(logfile == NULL) + logfiles[5] = fopen("temp.log", "a"); + if(logfiles[5] == NULL) { - printf("Unable to open the log file\n"); + printf("Unable to open the temperature log file\n"); return false; } - start = clock(); return true; } void closeLog() { - fclose(logfile); + fclose(logfiles[5]); } void printx(severity s, msgfrom from, char* str, ...) @@ -57,11 +56,11 @@ void printx(severity s, msgfrom from, char* str, ...) char buffer1[MAX_BUFFER]; char buffer2[MAX_BUFFER]; va_list arglist; - float now = clock(); va_start(arglist, str); vsprintf(buffer1, str, arglist); - fprintf(logfile, "[%6.6f] : %s", (now - start)/CLOCKS_PER_SEC, buffer1); - fflush(logfile); + gettimeofday(&tv,NULL); + fprintf(logfiles[5], "[%10ld] : %s", tv.tv_usec, buffer1); + fflush(logfiles[5]); sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET); if(s>DEBUG) printf("%s", buffer2); -- libgit2 0.21.2