From bcfdd6568beb7c02fc2f47d42cf7447be4f14fc7 Mon Sep 17 00:00:00 2001 From: Sunguk Lee Date: Fri, 4 Nov 2016 00:34:52 +0900 Subject: [PATCH] Add datetime to log file @cgutman 's suggest https://github.com/moonlight-stream/moonlight-common-c/issues/23#issuecomment-257635449 --- src/global.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/global.c b/src/global.c index c3ef57a8..b030287c 100644 --- a/src/global.c +++ b/src/global.c @@ -17,9 +17,11 @@ * along with Moonlight; if not, see . */ +#include #include #include #include +#include #include "config.h" #include "debug.h" @@ -35,13 +37,24 @@ void DEBUG_PRINT(const char *s, ...) { return; } - va_list va; - char buffer[1024]; + char buffer[1024] = {0}; + + SceDateTime time; + sceRtcGetCurrentClock(&time, 0); + + snprintf(buffer, 26, "%04d%02d%02d %02d:%02d:%02d.%06d ", + time.year, time.month, time.day, + time.hour, time.minute, time.second, + time.microsecond); + va_list va; va_start(va, s); - vsprintf(buffer, s, va); + int len = vsnprintf(&buffer[25], 998, s, va); va_end(va); fprintf(config.log_file, buffer); + if (buffer[len + 24] != '\n') { + fprintf(config.log_file, "\n"); + } fflush(config.log_file); }