Commit c0152e3d464cc775df900bcfdb361ed99f647abc
1 parent
b8e91a2f
Separated log files
Complete timestamp format
Showing
1 changed file
with
40 additions
and
10 deletions
Show diff stats
printx.c
@@ -27,27 +27,57 @@ void removeCharFromString(char c, char *str) | @@ -27,27 +27,57 @@ void removeCharFromString(char c, char *str) | ||
27 | 27 | ||
28 | bool initLog() | 28 | bool initLog() |
29 | { | 29 | { |
30 | - //char filename[FILENAME_LENGTH]; | ||
31 | - //time_t now = time(NULL); | 30 | + logfiles[0] = fopen("log/main.log", "a"); |
31 | + if(logfiles[0] == NULL) | ||
32 | + { | ||
33 | + printf("Unable to open the main log file\n"); | ||
34 | + return false; | ||
35 | + } | ||
36 | + logfiles[1] = fopen("log/ui.log", "a"); | ||
37 | + if(logfiles[1] == NULL) | ||
38 | + { | ||
39 | + printf("Unable to open the UI log file\n"); | ||
40 | + return false; | ||
41 | + } | ||
42 | + | ||
43 | + logfiles[2] = fopen("log/nfc.log", "a"); | ||
44 | + if(logfiles[2] == NULL) | ||
45 | + { | ||
46 | + printf("Unable to open the NFC log file\n"); | ||
47 | + return false; | ||
48 | + } | ||
32 | 49 | ||
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"); | 50 | + logfiles[3] = fopen("log/hvc.log", "a"); |
51 | + if(logfiles[3] == NULL) | ||
52 | + { | ||
53 | + printf("Unable to open the HVC log file\n"); | ||
54 | + return false; | ||
55 | + } | ||
37 | 56 | ||
38 | - logfiles[5] = fopen("temp.log", "a"); | 57 | + logfiles[4] = fopen("log/bus.log", "a"); |
58 | + if(logfiles[4] == NULL) | ||
59 | + { | ||
60 | + printf("Unable to open the BUS log file\n"); | ||
61 | + return false; | ||
62 | + } | ||
63 | + | ||
64 | + logfiles[5] = fopen("log/temp.log", "a"); | ||
39 | if(logfiles[5] == NULL) | 65 | if(logfiles[5] == NULL) |
40 | { | 66 | { |
41 | printf("Unable to open the temperature log file\n"); | 67 | printf("Unable to open the temperature log file\n"); |
42 | return false; | 68 | return false; |
43 | } | 69 | } |
44 | 70 | ||
45 | - | ||
46 | return true; | 71 | return true; |
47 | } | 72 | } |
48 | 73 | ||
49 | void closeLog() | 74 | void closeLog() |
50 | { | 75 | { |
76 | + fclose(logfiles[0]); | ||
77 | + fclose(logfiles[1]); | ||
78 | + fclose(logfiles[2]); | ||
79 | + fclose(logfiles[3]); | ||
80 | + fclose(logfiles[4]); | ||
51 | fclose(logfiles[5]); | 81 | fclose(logfiles[5]); |
52 | } | 82 | } |
53 | 83 | ||
@@ -59,8 +89,8 @@ void printx(severity s, msgfrom from, char* str, ...) | @@ -59,8 +89,8 @@ void printx(severity s, msgfrom from, char* str, ...) | ||
59 | va_start(arglist, str); | 89 | va_start(arglist, str); |
60 | vsprintf(buffer1, str, arglist); | 90 | vsprintf(buffer1, str, arglist); |
61 | gettimeofday(&tv,NULL); | 91 | gettimeofday(&tv,NULL); |
62 | - fprintf(logfiles[5], "[%10ld] : %s", tv.tv_usec, buffer1); | ||
63 | - fflush(logfiles[5]); | 92 | + fprintf(logfiles[from], "[%10ld.%06ld] : %s", tv.tv_sec, tv.tv_usec, buffer1); |
93 | + fflush(logfiles[from]); | ||
64 | sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET); | 94 | sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET); |
65 | if(s>DEBUG) | 95 | if(s>DEBUG) |
66 | printf("%s", buffer2); | 96 | printf("%s", buffer2); |