Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions include/fluent-bit/flb_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@
#define FLB_PACK_JSON_PRIMITIVE JSMN_PRIMITIVE

/* Date formats */
#define FLB_PACK_JSON_DATE_DOUBLE 0
#define FLB_PACK_JSON_DATE_ISO8601 1
#define FLB_PACK_JSON_DATE_EPOCH 2
#define FLB_PACK_JSON_DATE_DOUBLE 0
#define FLB_PACK_JSON_DATE_ISO8601 1
#define FLB_PACK_JSON_DATE_EPOCH 2
#define FLB_PACK_JSON_DATE_JAVA_SQL_TIMESTAMP 3

/* Specific ISO8601 format */
#define FLB_PACK_JSON_DATE_ISO8601_FMT "%Y-%m-%dT%H:%M:%S"

/* Specific Java SQL Timestamp format */
#define FLB_PACK_JSON_DATE_JAVA_SQL_TIMESTAMP_FMT "%Y-%m-%d %H:%M:%S"

/* JSON formats (modes) */
#define FLB_PACK_JSON_FORMAT_NONE 0
#define FLB_PACK_JSON_FORMAT_JSON 1
Expand Down
17 changes: 17 additions & 0 deletions src/flb_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ int flb_pack_to_json_date_type(const char *str)
if (strcasecmp(str, "double") == 0) {
return FLB_PACK_JSON_DATE_DOUBLE;
}
else if (strcasecmp(str, "java_sql_timestamp") == 0) {
return FLB_PACK_JSON_DATE_JAVA_SQL_TIMESTAMP;
}
else if (strcasecmp(str, "iso8601") == 0) {
return FLB_PACK_JSON_DATE_ISO8601;
}
Expand Down Expand Up @@ -883,6 +886,20 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
case FLB_PACK_JSON_DATE_DOUBLE:
msgpack_pack_double(&tmp_pck, flb_time_to_double(&tms));
break;
case FLB_PACK_JSON_DATE_JAVA_SQL_TIMESTAMP:
/* Format the time, use microsecond precision not nanoseconds */
gmtime_r(&tms.tm.tv_sec, &tm);
s = strftime(time_formatted, sizeof(time_formatted) - 1,
FLB_PACK_JSON_DATE_JAVA_SQL_TIMESTAMP_FMT, &tm);

len = snprintf(time_formatted + s,
sizeof(time_formatted) - 1 - s,
".%06" PRIu64,
(uint64_t) tms.tm.tv_nsec / 1000);
s += len;
msgpack_pack_str(&tmp_pck, s);
msgpack_pack_str_body(&tmp_pck, time_formatted, s);
break;
case FLB_PACK_JSON_DATE_ISO8601:
/* Format the time, use microsecond precision not nanoseconds */
gmtime_r(&tms.tm.tv_sec, &tm);
Expand Down