From f660bbd1bfed3fbd36d684cd2f09ca1520520557 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Tue, 11 Jun 2019 19:33:56 +0100 Subject: Prepend timestamps when writing to the debug log file. --- functions.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'functions.c') 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); -- cgit v1.2.3