Skip to content

Commit

Permalink
add millisecond precision to log timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Nov 6, 2024
1 parent 5bf5754 commit 54120e4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1462,9 +1462,9 @@ void gm_log( int lvl, const char *text, ... ) {
char buffer1[GM_BUFFERSIZE];
char buffer2[GM_BUFFERSIZE];
char buffer3[GM_BUFFERSIZE];
time_t t;
va_list ap;
struct timeval tv;
struct tm now;
va_list ap;
bool locked = false;

if(mod_gm_opt != NULL) {
Expand Down Expand Up @@ -1521,12 +1521,12 @@ void gm_log( int lvl, const char *text, ... ) {
}

/* set timestring */
t = time(NULL);
localtime_r(&t, &now);
strftime(buffer1, sizeof(buffer1), "[%Y-%m-%d %H:%M:%S]", &now );
gettimeofday(&tv, NULL);
localtime_r(&tv.tv_sec, &now);
strftime(buffer1, sizeof(buffer1), "[%Y-%m-%d %H:%M:%S", &now);

/* set timestring */
snprintf(buffer2, sizeof(buffer2), "[%i][%s]", getpid(), level );
/* append milliseconds and pid */
snprintf(buffer2, sizeof(buffer2), ",%03ld][%i][%s]", tv.tv_usec/1000, getpid(), level);

va_start( ap, text );
vsnprintf( buffer3, GM_BUFFERSIZE, text, ap );
Expand Down

0 comments on commit 54120e4

Please sign in to comment.