How to show milliseconds since epoch human readable?
msvticket opened this issue · 4 comments
When configuring Kubernetes and components thereof to log in json format the standard is to put a timestamp in the field ts as float signifying milliseconds since epoch. For example 1710858913.7978325 for Tue Mar 19 14:35:13 2024 (UTC).
Can you make hl parse this and output a human readable time string? If yes, how?
Here is the responsible line of code: https://github.com/kubernetes/component-base/blob/9d90bf7eaa57df6d6e0dd316529274b3c5747f5f/logs/json/json.go#L71
You gave an example here 1710858913.7978325, but that is actually number of seconds since unix epoch.
And the line of code you referenced above is number of milliseconds since epoch.
Do you have at least one real log line in this format as an example?
Added support for floating point numbers in timestamps with automatic detection of units in #154.
Please have a look at v0.27.0-beta.3.
Hopefully this covers your use cases. Let me know if it doesn't.
You gave an example here 1710858913.7978325, but that is actually number of seconds since unix epoch. And the line of code you referenced above is number of milliseconds since epoch. Do you have at least one real log line in this format as an example?
Sorry, that was a copy-paste error on my behalf. Here is a real example from the autoscaler:
{"ts":1710923450736.8257,"caller":"eligibility/eligibility.go:104","msg":"Scale-down calculation: ignoring 2 nodes unremovable in the last 5m0s\n","v":1}
I'll try that beta.
That beta worked fine, thank you!