Reformatting log timestamp to include time-zone
The time logged is currently given as localtime without any timezone information. This is confusing in various scenarios. Examples: * If one is travelling across time-zones and the timestamps in the log appear out of order. * Comparing dates with `datediff` gives an offset by the time-zone This patch would reformat the time-stamp to a full ISO-8601 version. It includes the 'T' separating date and time including seconds. Old: [2019-03-04 16:15] New: [2019-03-04T16:15:45-05:00] Signed-off-by: Florian Wehner <florian@whnr.de> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
c0e9be7973
commit
c61cd050f9
1 changed files with 5 additions and 3 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/* libalpm */
|
/* libalpm */
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -38,11 +39,12 @@ static int _alpm_log_leader(FILE *f, const char *prefix)
|
||||||
{
|
{
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm *tm = localtime(&t);
|
struct tm *tm = localtime(&t);
|
||||||
|
int length = 32;
|
||||||
|
char timestamp[length];
|
||||||
|
|
||||||
/* Use ISO-8601 date format */
|
/* Use ISO-8601 date format */
|
||||||
return fprintf(f, "[%04d-%02d-%02d %02d:%02d] [%s] ",
|
strftime(timestamp,length,"%FT%X%z", tm);
|
||||||
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
return fprintf(f, "[%s] [%s] ", timestamp, prefix);
|
||||||
tm->tm_hour, tm->tm_min, prefix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A printf-like function for logging.
|
/** A printf-like function for logging.
|
||||||
|
|
Loading…
Add table
Reference in a new issue