/* * Append a RFC 5424 formatted timestamp to buffer buf, expand as needed * */ void _xrfc5424timecat(char **buf, bool msec) { char p[64] = ""; char z[12] = ""; struct timeval tv; struct tm tm; if (gettimeofday(&tv, NULL) == -1) fprintf(stderr, "gettimeofday() failed\n"); if (!slurm_localtime_r(&tv.tv_sec, &tm)) fprintf(stderr, "localtime_r() failed\n"); if (strftime(p, sizeof(p), "%Y-%m-%dT%T", &tm) == 0) fprintf(stderr, "strftime() returned 0\n"); /* The strftime %z format creates timezone offsets of the form * (+/-)hhmm, whereas the RFC 5424 format is (+/-)hh:mm. So * shift the minutes one step back and insert the semicolon. */ if (strftime(z, sizeof(z), "%z", &tm) == 0) fprintf(stderr, "strftime() returned 0\n"); z[5] = z[4]; z[4] = z[3]; z[3] = ':'; if (msec) _xstrfmtcat(buf, "%s.%3.3d%s", p, (int)(tv.tv_usec / 1000), z); else _xstrfmtcat(buf, "%s%s", p, z); }
/* * Append a ISO 8601 formatted timestamp to buffer buf, expand as needed */ void _xiso8601timecat(char **buf, bool msec) { char p[64] = ""; struct timeval tv; struct tm tm; if (gettimeofday(&tv, NULL) == -1) fprintf(stderr, "gettimeofday() failed\n"); if (!slurm_localtime_r(&tv.tv_sec, &tm)) fprintf(stderr, "localtime_r() failed\n"); if (strftime(p, sizeof(p), "%Y-%m-%dT%T", &tm) == 0) fprintf(stderr, "strftime() returned 0\n"); if (msec) _xstrfmtcat(buf, "%s.%3.3d", p, (int)(tv.tv_usec / 1000)); else _xstrfmtcat(buf, "%s", p); }
/* * Append a ISO 8601 formatted timestamp to buffer buf, expand as needed */ void _xiso8601timecat(char **buf) { char p[64] = ""; struct timeval tv; struct tm tm; if (gettimeofday(&tv, NULL) == -1) fprintf(stderr, "gettimeofday() failed\n"); if (!localtime_r(&tv.tv_sec, &tm)) fprintf(stderr, "localtime_r() failed\n"); if (strftime(p, sizeof(p), "%Y-%m-%dT%T", &tm) == 0) fprintf(stderr, "strftime() returned 0\n"); #if defined LOG_TIME_MSEC /* Add millisecond data */ _xstrfmtcat(buf, "%s.%3.3d", p, (int)(tv.tv_usec / 1000)); #else _xstrfmtcat(buf, "%s", p); #endif }