Skip to content

Instantly share code, notes, and snippets.

@poohsen
Last active February 5, 2024 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poohsen/ff5e3c2a9a616c475e16ffee29f02f29 to your computer and use it in GitHub Desktop.
Save poohsen/ff5e3c2a9a616c475e16ffee29f02f29 to your computer and use it in GitHub Desktop.
A better 'echo' for BASH script output
log () {
current_date=$(date +"%Y-%m-%d %H:%M:%S,%N")
ns=${current_date:20:9}
# turn ns to ms using rounding
rounded_millis=$(printf "%.0f" $(echo "scale=6;$ns/1000000" | bc))
msg=$1
echo "${current_date:0:20}${rounded_millis} - ${msg}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment