Commit b8e91a2f0aca34f673c43e4d07a7d7e7e4917099
1 parent
80e0082e
Displaying everything on the temp log
Showing
1 changed file
with
16 additions
and
17 deletions
Show diff stats
printx.c
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | #include <stdarg.h> |
4 | 4 | #include <stdbool.h> |
5 | 5 | #include <string.h> |
6 | -#include <time.h> | |
6 | +#include <sys/time.h> | |
7 | 7 | #include "printx.h" |
8 | 8 | #include "ui.h" |
9 | 9 | |
... | ... | @@ -13,8 +13,8 @@ |
13 | 13 | |
14 | 14 | FILE* logfiles[5] = {NULL, NULL, NULL, NULL, NULL}; |
15 | 15 | char s_color[4][12] = {"\x1b[01;31m", "\x1b[01;33m", "\x1b[01;32m", "\x1b[01;36m"}; |
16 | -char f_name[5][5] = {"MAIN", "UI ", "NFC ", "HVC ", "BUS "}; | |
17 | -float start; | |
16 | +char f_name[6][5] = {"MAIN", "UI ", "NFC ", "HVC ", "BUS ", "TEMP"}; | |
17 | +struct timeval tv; | |
18 | 18 | |
19 | 19 | void removeCharFromString(char c, char *str) |
20 | 20 | { |
... | ... | @@ -27,29 +27,28 @@ void removeCharFromString(char c, char *str) |
27 | 27 | |
28 | 28 | bool initLog() |
29 | 29 | { |
30 | - char filename[FILENAME_LENGTH]; | |
31 | - time_t now = time(NULL); | |
30 | + //char filename[FILENAME_LENGTH]; | |
31 | + //time_t now = time(NULL); | |
32 | 32 | |
33 | - strftime(filename, FILENAME_LENGTH, "%F-%T:%d", localtime(&now)); | |
34 | - setStartTime(filename); | |
35 | - strftime(filename, FILENAME_LENGTH, "log/%F-%T:%d", localtime(&now)); | |
36 | - strcat(filename, ".log"); | |
33 | + //strftime(filename, FILENAME_LENGTH, "%F-%T:%d", localtime(&now)); | |
34 | + //setStartTime(filename); | |
35 | + //strftime(filename, FILENAME_LENGTH, "log/%F-%T:%d", localtime(&now)); | |
36 | + //strcat(filename, ".log"); | |
37 | 37 | |
38 | - logfile = fopen(filename, "w"); | |
39 | - if(logfile == NULL) | |
38 | + logfiles[5] = fopen("temp.log", "a"); | |
39 | + if(logfiles[5] == NULL) | |
40 | 40 | { |
41 | - printf("Unable to open the log file\n"); | |
41 | + printf("Unable to open the temperature log file\n"); | |
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | |
45 | - start = clock(); | |
46 | 45 | |
47 | 46 | return true; |
48 | 47 | } |
49 | 48 | |
50 | 49 | void closeLog() |
51 | 50 | { |
52 | - fclose(logfile); | |
51 | + fclose(logfiles[5]); | |
53 | 52 | } |
54 | 53 | |
55 | 54 | void printx(severity s, msgfrom from, char* str, ...) |
... | ... | @@ -57,11 +56,11 @@ void printx(severity s, msgfrom from, char* str, ...) |
57 | 56 | char buffer1[MAX_BUFFER]; |
58 | 57 | char buffer2[MAX_BUFFER]; |
59 | 58 | va_list arglist; |
60 | - float now = clock(); | |
61 | 59 | va_start(arglist, str); |
62 | 60 | vsprintf(buffer1, str, arglist); |
63 | - fprintf(logfile, "[%6.6f] : %s", (now - start)/CLOCKS_PER_SEC, buffer1); | |
64 | - fflush(logfile); | |
61 | + gettimeofday(&tv,NULL); | |
62 | + fprintf(logfiles[5], "[%10ld] : %s", tv.tv_usec, buffer1); | |
63 | + fflush(logfiles[5]); | |
65 | 64 | sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET); |
66 | 65 | if(s>DEBUG) |
67 | 66 | printf("%s", buffer2); | ... | ... |