kcat
kcat copied to clipboard
Show message timestamp as UTC ISO8601 format
Although I think currently the %T
format string token just prints the unix epoch timestamp as read from kafka, for quick debug purposes it would be very useful to have a timestamp in more readable format, for example ISO8601 in UTC. Currently I have to copy paste the timestamps to a converter in order to make sense of it.
If there already is an alternative I'm happy to hear about it!
That does make sense.
As a workaround you can use jq to reformat the timestamp: https://stackoverflow.com/questions/36853202/jq-dates-and-unix-timestamps
I have done a quick change #216 to display human readable form next to epoch. You can build it from https://github.com/wkujawa/kafkacat
Example for format 'Timestamp: %T':
Timestamp: 1576098689443 (Wed 2019-12-11 22:11:29.443 CET)
It should be new format specifier but that way is good for me. Feel free to do whatever you like with it. I can also modify it further.
Example of the workaround mentioned by @edenhill:
kcat -C \
-b $KAFKA_BROKER \
-t $KAFKA_TOPIC \
-o beginning \
-J \
-e \
| jq '.ts |= (. / 1000 | strftime("%Y-%m-%d %H:%M:%S"))'
Edit: fixed according to the comments directly below
Example of the workaround mentioned by @edenhill:
kcat -C \ -b $KAFKA_BROKER \ -t $KAFKA_TOPIC \ -o beginning \ -J \ -e \ | jq '.ts |= (. / 1000 | strftime("%Y-%m-%d %H:%m:%S"))'
@fletchgqc @edenhill Thanks a lot. btw. you probably meant "%Y-%m-%d %H:%M:%S"
For anyone who, like me, has trouble seeing the difference: the original comment by @fletchgqc erroneously uses m
(month) not M
(minute) for the time format
--------------Δ----
"%Y-%m-%d %H:%m:%S"
"%Y-%m-%d %H:%M:%S