-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from jszczerbinsky/dev
v2.1.2
- Loading branch information
Showing
22 changed files
with
2,030 additions
and
1,441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,10 @@ build/ | |
|
||
.vscode | ||
|
||
tags | ||
types_c.taghl | ||
*~ | ||
|
||
# Prerequisites | ||
*.d | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <glib.h> | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
#include <time.h> | ||
|
||
#include "../common.h" | ||
|
||
void clearlog() | ||
{ | ||
char path[PATH_MAX]; | ||
getLogPath(path); | ||
|
||
FILE *file = fopen(path, "w"); | ||
fclose(file); | ||
} | ||
|
||
void printlog(int type, const char *str, ...) | ||
{ | ||
char path[PATH_MAX]; | ||
getLogPath(path); | ||
|
||
FILE *file = fopen(path, "a"); | ||
|
||
time_t t; | ||
time(&t); | ||
struct tm *time = localtime(&t); | ||
|
||
char *typePrefix = ""; | ||
|
||
switch (type) | ||
{ | ||
case LOG_ERROR: | ||
typePrefix = "ERROR"; | ||
break; | ||
case LOG_INFO: | ||
typePrefix = "INFO"; | ||
break; | ||
case LOG_WARNING: | ||
typePrefix = "WARNING"; | ||
break; | ||
} | ||
|
||
fprintf( | ||
file, | ||
"%d-%02d-%02d %02d:%02d:%02d %s: ", | ||
time->tm_year + 1900, | ||
time->tm_mon + 1, | ||
time->tm_mday, | ||
time->tm_hour, | ||
time->tm_min, | ||
time->tm_sec, | ||
typePrefix | ||
); | ||
|
||
va_list args; | ||
va_start(args, str); | ||
vfprintf(file, str, args); | ||
va_end(args); | ||
|
||
fprintf(file, "\n"); | ||
|
||
fclose(file); | ||
} | ||
|
||
char *readLogFile() | ||
{ | ||
char path[PATH_MAX]; | ||
getLogPath(path); | ||
|
||
FILE *file = fopen(path, "r"); | ||
|
||
fseek(file, 0, SEEK_END); | ||
int len = ftell(file); | ||
fseek(file, 0, SEEK_SET); | ||
|
||
char *buff = malloc((len + 1) * sizeof(char)); | ||
fread(buff, sizeof(char), len, file); | ||
buff[len] = '\0'; | ||
|
||
fclose(file); | ||
|
||
return buff; | ||
} |
Oops, something went wrong.