How can I log POST request data in JSON


#1

Sending this to echo

curl -s -X POST -H "Content-type: application/json" -d '{
	"url": "https://google.com/",
	"time-wait": 5,
}' 'http://127.0.0.1:1323/screenshot'

would like to log url inside json


#2

When you say that you want to log JSON are you talking about updating a varible that is in memory, a flatfile or a JSON like nosql database? That will greatly influence how this is handled.


#3

I just want to print to logger part of request body

for example,

time=2018-04-02T15:42:11+03:00, remote_ip=127.0.0.1, method=POST, uri=/screenshot, status=200, remote_url=https://google.com/

and if error occurs print error message

time=2018-04-02T15:42:11+03:00, remote_ip=127.0.0.1, method=POST, uri=/screenshot, status=200, remote_url=https://google.com/, err=no such file or directory


#4

The default logger middleware doesn’t allow you to specify custom variable. You will need to handler this in your own middleware.


#5

https://forum.labstack.com/t/logging-request-and-response-to-mongodb/528

Try it bro!