Last active
February 5, 2024 09:01
-
-
Save poohsen/ff5e3c2a9a616c475e16ffee29f02f29 to your computer and use it in GitHub Desktop.
A better 'echo' for BASH script output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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