-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Allow json output for logging (not access logs) #13636
Description
Title: Allow json output for logging (not access logs)
Description:
I would like to output logs as JSON. For example, {"level":"info","time":"2020-10-19T14:17:05.010719Z","scope":"config","msg":"loading 1 cluster(s)"}
This is almost possible with envoy --log-format '{"level":"%l","time":"%Y-%m-%dT%T.%fZ","scope":"%n","msg":"%v"}'. however, the message is not escaped, leading to invalid multiline logs:
{"level":"info","time":"2020-10-19T14:17:05.010596Z","scope":"main","msg":"runtime: layers:
- name: base
static_layer:
{}
- name: admin
admin_layer:
{}"}
If we add --log-format-escaped, we end up with our quotes being escaped, like {\"level\":\"info\",\"time\":\"2020-10-19T14:19:47.299995Z\",\"scope\":\"main\",\"msg\":\"exiting\"}
What I am looking for is some way to get our desired output:
{"level":"info","time":"2020-10-19T14:20:32.015724Z","scope":"main","msg":"runtime: layers:\\n - name: base\\n static_layer:\\n {}\\n - name: admin\n admin_layer:\\n {}"}. Here we get valid json, and if I were to pass jq .msg -r on it I would get the original message back