curl: format stdout for better logging of requests
Curl is an excellent tool and provides the -w parameter to format your output, this can be super handy in case you want to write curl…
Curl is an excellent tool and provides the -w parameter to format your output, this can be super handy in case you want to write curl output to a log file but select what you will print.
Create the following file and save it as curl-fmt.txt%{url_effective},%{time_total},%{size_download},%{http_code}\n
For our testing purposes i will use https://www.google.com , in the same directory as curl-fmt.txt entercurl -s -o /dev/null -w "@curl-fmt.txt" -k 'https://www.google.com'
The output you will get would is the bellow that relates to the options of the curl-fmt.txt.https://www.google.com/,0.522977,15296,200
Now, suppose that you want to prepend a timestamp on each line, i didnt find a way to do this using curl but i found a very handy tool named ts. you can use curl and ts like thiscurl -s -o /dev/null -w "@curl-fmt.txt" -k 'https://www.google.com' | ts '%Y-%m-%dT%H:%M:%S,'
ts will prepend a timestamp2022-09-01T16:19:04, https://www.google.com/,0.553149,15353,200
I hope you found this article useful :)