Help us shape the future of Go! Take the 2026 Go Developer Survey

dockerlogstream

command module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

README

![GoBuilder Download](https://badge.luzifer.io/v1/badge?color=5d79b5&title=Download&text=on GoBuilder) Build Status

Jimdo / dockerlogstream

This project makes use of the fluentd log-driver implemented in Docker v1.8. Instead of fetching the logs using the docker.sock or having to run a ruby container with fluentd you can run this as a single binary on your system. The log format is 100% compatible to the format used by fluentd.

Usage

As a systemd unit
  • Deploy the binary to /usr/local/bin/dockerlogstream
  • Create following unit file
[Unit]
Description=DockerLogStream
After=docker.service
[Service]
Type=simple
TimeoutStartSec=0
TimeoutStopSec=0
Restart=always
RestartSec=30
SyslogIdentifier=dockerlogstream
ExecStart=/usr/local/bin/dockerlogstream --endpoint=...
As a docker container
# docker run -ti -v /var/run/docker.sock:/var/run/docker.sock -p 127.0.0.1:24224:24224 Jimdo/dockerlogstream --endpoint=...
Configuring your containers to log into the dockerlogstream

You need to add the option --log-driver=fluentd to you docker run command:

# docker run --log-driver=fluentd --rm -ti alpine echo "Hello World!"

If you want to use this method for all containers on your host you also can modify the DOCKER_OPTS variable for your docker deamon:

DOCKER_OPTS="--log-driver=fluentd"

JavaScript line formatter

The log line formatting (and filtering) are done by simple JavaScript files. One example for a more complex solution can be found in the lineconverter.js file inside this repository.

// We will get some variables set from the Go program:
// dockerlogstream    Object{}    Interaction interface for the program

// Inside dockerlogstream there are two functions and two properties available:
// Message                Object{}  Message as struct as specified in types.go
// Hostname               string    Hostname of the machine the program is running on
// SendLogLine(string)              Pass your processed log line to this function
// SkipLogLine()                    If you do filtering in here you can skip lines with this function

Given this you can do a very simple line formatter using this JavaScript code:

var message = dockerlogstream.Message;
dockerlogstream.SendLogLine(
  message.Time.Format("Jan 2 15:04:05") + " " +
  dockerlogstream.Hostname + " " +
  message.Container.Names[0].substring(1) + ": " +
  message.Data);

For more examples see the example folder in this repository.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL