1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
# dlog
Go library to parse the binary Docker Logs stream into plain text.
[](https://godoc.org/github.com/ahmetalpbalkan/dlog)
[](https://travis-ci.org/ahmetalpbalkan/dlog)
[](https://coveralls.io/github/ahmetalpbalkan/dlog?branch=master)
[](https://goreportcard.com/report/github.com/ahmetalpbalkan/dlog)
`dlog` offers a single method: `NewReader(r io.Reader) io.Reader`. You are
supposed to give the response body of the `/containers/<id>/logs`. The returned
reader strips off the log headers and just gives the plain text to be used.
Here is how a log line from container looks like in the the raw docker logs
stream:
```text
01 00 00 00 00 00 00 1f 52 6f 73 65 73 20 61 72 65 ...
│ ─────┬── ─────┬───── R o s e s a r e ...
│ │ │
└stdout │ │
│ └─ 0x0000001f = log message is 31 bytes
unused
```
You can get the logs stream from [go-dockerclient][gocl]'s [`Logs()`][gocl-logs]
method, or by calling the [container logs endpoint][rapi] direclty via the UNIX socket
directly.
See [`example_test.go`](./example_test.go) for an example usage.
This library is written in vanilla Go and has no external dependencies.
[gocl]: https://github.com/fsouza/go-dockerclient
[gocl-logs]: https://godoc.org/github.com/fsouza/go-dockerclient#Client.Logs
[rapi]: https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/get-container-logs
-----
Licensed under Apache 2.0. Copyright 2017 [Ahmet Alp Balkan][ab].
[ab]: https://ahmetalpbalkan.com/
|