github.com/Jimdo/dockerlogstream


Properties

Last built 5 months ago using go version go1.7.1 linux/amd64 and 131 seconds of time

Downloads
Filename
File Size
 
dockerlogstream_master_darwin-386.zip
3.1MiB
dockerlogstream_master_darwin-amd64.zip
3.2MiB
dockerlogstream_master_linux-386.zip
3.1MiB
dockerlogstream_master_linux-amd64.zip
3.2MiB
dockerlogstream_master_linux-arm.zip
3.0MiB
dockerlogstream_master_windows-386.zip
3.0MiB
dockerlogstream_master_windows-amd64.zip
3.2MiB
Project-Readme for this version

License: Apache v2.0 GoBuilder Download 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.