Skip to content

Commit

Permalink
Merge branch 'duplicate-logs' of https://github.com/gliderlabs/logspout
Browse files Browse the repository at this point in the history
… into duplicate-logs
  • Loading branch information
mattatcha committed Jul 29, 2016
2 parents e6afe44 + 357e669 commit d665381
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 9 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ EXPOSE 80
COPY . /src
RUN cd /src && ./build.sh "$(cat VERSION)"

ONBUILD COPY ./build.sh /src/build.sh
ONBUILD COPY ./modules.go /src/modules.go
ONBUILD RUN cd /src && ./build.sh "$(cat VERSION)-custom"
6 changes: 6 additions & 0 deletions Dockerfile.custom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM iron/go:dev

WORKDIR /app
ADD . /app

ENTRYPOINT ["./logspout"]
26 changes: 26 additions & 0 deletions MODULES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Instructions on how to build/test your own modules.

## Getting Started

1. Fork this repository
1. Create a new repository for your adapter
1. Copy something like [raw.go](https://github.com/gliderlabs/logspout/blob/master/adapters/raw/raw.go) to get started.
1. Add your module to modules.go

Now build and run logspout with your adapter, replace SYSLOG with your own syslog url.

```sh
SYSLOG=syslog://logs.papertrailapp.com:55555 ./run-custom.sh
```

Now let's add your new adapter to the running logspout (replace address below with your final stats destination):

```sh
curl http://localhost:8000/routes -d '{
"adapter": "myadapter",
"filter_sources": ["stdout" ,"stderr"],
"address": "localhost:1234"
}'
```

Now any log messages that come out of any container on your machine will go through your adapter.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,23 @@ The simplest way to use logspout is to just take all logs and ship to a remote s
gliderlabs/logspout \
syslog://logs.papertrailapp.com:55555

logspout will gather logs from other containers that are started **without the `-t` option**.
logspout will gather logs from other containers that are started **without the `-t` option** and are configured with a logging driver that works with `docker logs` (`journald` and `json-file`).

To see what data is used for syslog messages, see the [syslog adapter](http://github.com/gliderlabs/logspout/blob/master/adapters) docs.

#### Ignoring specific containers

You can tell logspout to ignore specific containers by setting an environment variable when starting your container, like so:-

$ docker run -d -e 'LOGSPOUT=ignore' image
$ docker run -d -e 'LOGSPOUT=ignore' image

Or, by adding a label which you define by setting an environment variable when running logspout:

$ docker run --name="logspout" \
-e EXCLUDE_LABEL=logspout.exclude \
--volume=/var/run/docker.sock:/var/run/docker.sock \
gliderlabs/logspout
$ docker run -d --label logspout.exclude=true image

#### Inspect log streams using curl

Expand Down
6 changes: 6 additions & 0 deletions build-custom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set -ex

docker run --rm -v "$GOPATH":/go -w /go/src/github.com/gliderlabs/logspout -e "GOPATH=/go" iron/go:dev sh -c 'go build -o logspout'

# Can build the image too
# docker build -t gliderlabs/logspout:latest .
20 changes: 13 additions & 7 deletions router/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,26 @@ func normalID(id string) string {
return id
}

func logDriverSupported(container *docker.Container) bool {
switch container.HostConfig.LogConfig.Type {
case "json-file", "journald":
return true
default:
return false
}
}

func ignoreContainer(container *docker.Container) bool {
for _, kv := range container.Config.Env {
kvp := strings.SplitN(kv, "=", 2)
if len(kvp) == 2 && kvp[0] == "LOGSPOUT" && strings.ToLower(kvp[1]) == "ignore" {
return true
}
}
excludeLabel := getopt("EXCLUDE_LABEL", "")
if value, ok := container.Config.Labels[excludeLabel]; ok {
return len(excludeLabel) > 0 && strings.ToLower(value) == "true"
}
return false
}

Expand Down Expand Up @@ -143,11 +156,9 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents) {

outrd, outwr := io.Pipe()
errrd, errwr := io.Pipe()
p.mu.Lock()
p.pumps[id] = newContainerPump(container, outrd, errrd)
p.mu.Unlock()
p.update(event)
debug("pump.pumpLogs():", id, "started")
go func() {
err := p.client.Logs(docker.LogsOptions{
Container: id,
Expand All @@ -162,11 +173,6 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents) {
if err != nil {
debug("pump.pumpLogs():", id, "stopped:", err)
}
outwr.Close()
errwr.Close()
p.mu.Lock()
delete(p.pumps, id)
p.mu.Unlock()
}()
}

Expand Down
9 changes: 9 additions & 0 deletions run-custom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -ex

./build-custom.sh
docker build --file Dockerfile.custom -t mylogspouter .
docker run --rm --name=logspout \
-v=/var/run/docker.sock:/var/run/docker.sock \
-p 8000:80 \
mylogspouter \
${SYSLOG}

0 comments on commit d665381

Please sign in to comment.