mendhak / docker-http-https-echo

Docker image that echoes request data as JSON; listens on HTTP/S, useful for debugging.
https://code.mendhak.com/docker-http-https-echo/
MIT License
621 stars 136 forks source link

Option to change log format to JSON #59

Open MichaelSasser opened 10 months ago

MichaelSasser commented 10 months ago

First off, thank you for putting in the work. This is a super helpful project.


I would appreciate it if it was possible to enable an option besides LOG_WITHOUT_NEWLINE and DISABLE_REQUEST_LOGS to have one line per request in the log output formatted as JSON.

One of the reasons is that I don't use the logs on the host machine directly. They might get scraped and processed out of order by Loki, so they might not end up next to each other. The second reason is that it would be simpler to parse them when they had the same format.

mendhak commented 9 months ago

Hi I tried rereading a few times, but I didn't understand, there's already one line per request in JSON format?

I ran:

docker run -e DISABLE_REQUEST_LOGS=true -e LOG_WITHOUT_NEWLINE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:30

And the log lines look like this:

{"path":"/v1/completions","headers":{"host":"localhost:8080","user-agent":"curl/7.81.0","accept":"*/*","content-type":"application/json"},"method":"GET","body":"","fresh":false,"hostname":"localhost","ip":"::ffff:172.17.0.1","ips":[],"protocol":"http","query":{},"subdomains":[],"xhr":false,"os":{"hostname":"0970983690cd"},"connection":{}}
{"path":"/aaaaaaa/bbbbbbbbb/ccccccccc","headers":{"host":"localhost:8080","user-agent":"curl/7.81.0","accept":"*/*","content-type":"application/json"},"method":"GET","body":"","fresh":false,"hostname":"localhost","ip":"::ffff:172.17.0.1","ips":[],"protocol":"http","query":{},"subdomains":[],"xhr":false,"os":{"hostname":"0970983690cd"},"connection":{}}