https://github.com/ahmetb/dlog
Go library to parse the Docker Logs stream
https://github.com/ahmetb/dlog
docker go log-collector log-stream
Last synced: about 1 year ago
JSON representation
Go library to parse the Docker Logs stream
- Host: GitHub
- URL: https://github.com/ahmetb/dlog
- Owner: ahmetb
- License: apache-2.0
- Created: 2017-01-04T05:02:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-05T20:53:56.000Z (over 9 years ago)
- Last Synced: 2025-05-06T18:07:38.595Z (about 1 year ago)
- Topics: docker, go, log-collector, log-stream
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 37
- Watchers: 3
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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//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/