Skip to content

Commit

Permalink
broker: add year to log timestamps
Browse files Browse the repository at this point in the history
Problem: Flux broker log timestamps do not contain the year. This
makes it difficult for users to determine when an error or other
log message occurred in historical job output files.

Add the year to log timestamps emitted by the broker.
  • Loading branch information
grondo committed Jan 23, 2025
1 parent 2088011 commit 014ace5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/broker/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,16 @@ static void log_timestamp (FILE *fp,
struct timeval tv;
char datetime[16]; /* 'MMM DD HH:MM:SS' */
char timezone[16]; /* TZ abbrev should be short, give 15 chars max */
char year[5]; /* 4 digit year */

if (flags & LOG_NO_TIMESTAMP)
return;
if (timestamp_parse (hdr->timestamp, &tm, &tv) < 0
|| strftime (datetime, sizeof (datetime), "%b %d %T", &tm) == 0
|| strftime (timezone, sizeof (timezone), "%Z", &tm) == 0)
|| strftime (timezone, sizeof (timezone), "%Z", &tm) == 0
|| strftime (year, sizeof (year), "%Y", &tm) == 0)
fprintf (fp, "%s ", hdr->timestamp);
fprintf (fp, "%s.%06ld %s ", datetime, (long)tv.tv_usec, timezone);
fprintf (fp, "%s.%06ld %s %s ", datetime, (long)tv.tv_usec, timezone, year);
}

/* Log a message to 'fp', if non-NULL.
Expand Down

0 comments on commit 014ace5

Please sign in to comment.