docker/docker — pull request #8948 by icecrime (2014-11-04 16:18:55+00:00)
Title: Proposal: structured logging and new --log-format daemon flag

The [`logrus`](https://github.com/Sirupsen/logrus) logging library was introduced by @LK4D4 in #8770 as a drop-in replacement for golang's log package (see also related issue #8921). This is a proposal to:
* Take advantage of `logrus` features, especially [structured logging](https://github.com/Sirupsen/logrus#fields)
* Seize the opportunity to review log levels and wording if necessary

This PR includes documentation changes and only starts implementing the changes on chosen source files to get an idea of what the output would end up looking like. Here's my first thoughts:
* Structure logging is appreciable, especially as it opens the door to JSON log output. However, it does make things a little weird from a human perspective as log messages become extremely short (e.g.: `API Call`) with many context fields following them (e.g.: `method=POST remoteAddr=@ uri=/v1.16/containers/8c227b1dadab2b3227bf3f60a7b5653ca7673a6d1bfd564bed13221d4c30a117/start`)
* The `logrus` default `TextFormatter` produces a lot of whitespace: I messily copied it in order to tweak the output format.

Let's discuss to see if it's worth applying this strategy to all Docker logs. (cc @crosbymichael, @dmp42 who expressed interest in our usage of `logrus`)

-------

Exemple standard output:

![Standard output screenshot](http://iceenmousse.free.fr/_upload/logrus_example.png)

Example JSON output:

```
$> docker -dD --log-format=json
{"job":"serveapi","jobArgs":["unix:///var/run/docker.sock"],"level":"debug","msg":"+job","time":"2014-11-04T16:11:22Z"}
{"address":"/var/run/docker.sock","level":"info","msg":"Listening for HTTP","proto":"unix","time":"2014-11-04T16:11:22Z"}
{"level":"debug","method":"POST","msg":"Registering API endpoint","route":"/exec/{name:.*}/resize","time":"2014-11-04T16:11:22Z"}
{"level":"debug","method":"POST","msg":"Registering API endpoint","route":"/auth","time":"2014-11-04T16:11:22Z"}
{"level":"debug","method":"POST","msg":"Registering API endpoint","route":"/exec/{name:.*}/start","time":"2014-11-04T16:11:22Z"}
{"level":"debug","method":"POST","msg":"Registering API endpoint","route":"/images/{name:.*}/push","time":"2014-11-04T16:11:22Z"}
{"level":"debug","method":"POST","msg":"Registering API endpoint","route":"/containers/{name:.*}/start","time":"2014-11-04T16:11:22Z"}
{"level":"debug","method":"POST","msg":"Registering API endpoint","route":"/images/create","time":"2014-11-04T16:11:22Z"}
```