summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-06-11 19:33:56 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-06-11 19:33:56 +0100
commitf660bbd1bfed3fbd36d684cd2f09ca1520520557 (patch)
tree78b60be1fc0c2ad16a90d4152b302a29f9b749d7 /functions.c
parent1979b37e4fa3c9b7ed8784cf8b52cfae74edd9a4 (diff)
Prepend timestamps when writing to the debug log file.
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/functions.c b/functions.c
index 4ea5a51..c23366d 100644
--- a/functions.c
+++ b/functions.c
@@ -103,8 +103,21 @@ void debugprint(int level, char *format, ...) {
return;
}
+ // Prepend a timestamp to each line
+ time_t rawtime;
+ struct tm * timeinfo;
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+ // Strip the trailing newline
+ char timestr[MAXCHAR];
+ snprintf(timestr, MAXCHAR, "%s", asctime(timeinfo));
+ timestr[strlen(timestr) - 1] = '\0';
+ if ((bytes = fprintf(fp, "%s: ", timestr)) < 0) {
+ debugprint(DEBUG_CRIT, "error: could not write timestamp to debug file.\n"); // TODO - This might not be useful if we can't write
+ }
+
if ((bytes = vfprintf(fp, format, args)) < 0) {
- debugprint(DEBUG_CRIT, "error: could not write to debug file.\n");
+ debugprint(DEBUG_CRIT, "error: could not write to debug file.\n"); // TODO - This might not be useful if we can't write
}
fclose(fp);