1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-22 18:23:25 +01:00

Add higher precision for logging timestamps

This commit is contained in:
jfreegman 2022-03-08 18:21:20 -05:00
parent 529d905bd0
commit 4f936e5f9c
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -37,6 +37,7 @@
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <termios.h>
#include <time.h>
@ -267,12 +268,14 @@ void cb_toxcore_logger(Tox *m, TOX_LOG_LEVEL level, const char *file, uint32_t l
fp = stderr;
}
const time_t t = time(NULL);
struct tm *tmp = gmtime(&t);
struct timeval tv;
gettimeofday(&tv, NULL);
struct tm tmp;
gmtime_r(&tv.tv_sec, &tmp);
char timestamp[200];
strftime(timestamp, sizeof(timestamp), "%F %T", tmp);
strftime(timestamp, sizeof(timestamp), "%F %T", &tmp);
fprintf(fp, "[%c] %s %s:%u(%s) - %s\n", tox_log_level_show(level)[0], timestamp, file, line, func, message);
fprintf(fp, "%c %s.%06ld %s:%u(%s) - %s\n", tox_log_level_show(level)[0], timestamp, tv.tv_usec, file, line, func, message);
fflush(fp);
}