size_t log_timestamp(char *s, size_t max) { if (!log) return _make_timestamp(s, max, "%Y-%m-%dT%T"); switch (log->fmt) { case LOG_FMT_RFC5424_MS: case LOG_FMT_RFC5424: { size_t written = _make_timestamp(s, max, "%Y-%m-%dT%T%z"); if (max >= 26 && written == 24) { /* 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. */ s[25] = '\0'; s[24] = s[23]; s[23] = s[22]; s[22] = ':'; return written + 1; } return written; } case LOG_FMT_SHORT: return _make_timestamp(s, max, "%b %d %T"); break; default: return _make_timestamp(s, max, "%Y-%m-%dT%T"); break; } }
size_t log_timestamp(char *s, size_t max) { #ifdef USE_RFC5424_TIME size_t written = _make_timestamp(s, max, "%Y-%m-%dT%T%z"); if (max >= 26 && written == 24) { /* 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. */ s[25] = '\0'; s[24] = s[23]; s[23] = s[22]; s[22] = ':'; return written + 1; } return written; #elif defined USE_ISO_8601 return _make_timestamp(s, max, "%Y-%m-%dT%T"); #else return _make_timestamp(s, max, "%b %d %T"); #endif }
size_t rfc2822_timestamp(char *s, size_t max) { return _make_timestamp(s, max, "%a, %d %b %Y %H:%M:%S %z"); }