docker-http-https-echo icon indicating copy to clipboard operation
docker-http-https-echo copied to clipboard

Option to change log format to JSON

Open MichaelSasser opened this issue 2 years ago • 1 comments

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.

MichaelSasser avatar Oct 22 '23 02:10 MichaelSasser

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":{}}

mendhak avatar Dec 03 '23 19:12 mendhak