Hacker News new | ask | show | jobs
by atomicstack 903 days ago
I use `ts` quite often in adhoc logging/monitoring contexts. Because it uses strftime() under the hood, it has automatic support for '%F' and '%T', which are much easier to type than '%Y-%m-%d' and '%H:%M:%S'. Plus, it also has support for high-resolution times via '%.T', '%.s', and '%.S':

  echo 'hello world' | ts '[%F %.T]'
  [2023-12-30 16:25:40.463640] hello world
3 comments

Assuming semi-recent bash(1), you can also get away with something like

    while read -r line; do printf '%(%F %T %s)T %s\n' "-1" "${line}"; done
as the right-hand side/reader of a shell pipe for most of what ts(1) offers. ("-1" makes the embedded strftime(3) format string assume the current time as its input).
I recommend zmwangx/ets package, it is the modern version of ts. I'm using it in CI/CD pipeline in gitlab for debugging performance.
Thanks a lot for the link, I needed an improved `ts` for a long time now.
The ‘logger’ command can also be useful.