Skip to content

Commit

Permalink
Merge pull request #321 from stevecalvert/tail-env
Browse files Browse the repository at this point in the history
Tail env
  • Loading branch information
michaelshobbs authored Sep 1, 2017
2 parents 69afdab + 70b47a8 commit b6a1988
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ You can route to multiple destinations by comma-separating the URIs:
raw://192.168.10.10:5000?filter.name=*_db,syslog+tls://logs.papertrailapp.com:55555?filter.name=*_app

#### Suppressing backlog tail
You can tell logspout to only display log entries since container "start" or "restart" event by setting a `BACKLOG=false` environment variable (equivalent to `docker logs --tail=0`):
You can tell logspout to only display log entries since container "start" or "restart" event by setting a `BACKLOG=false` environment variable (equivalent to `docker logs --since=0s`):

$ docker run -d --name="logspout" \
-e 'BACKLOG=false' \
Expand All @@ -99,6 +99,10 @@ The default behaviour is to output all logs since creation of the container (equ

> NOTE: Use of this option **may** cause the first few lines of log output to be missed following a container being started, if the container starts outputting logs before logspout has a chance to see them. If consistent capture of *every* line of logs is critical to your application, you might want to test thorougly and/or avoid this option (at the expense of getting the entire backlog for every restarting container). This does not affect containers that are removed and recreated.

#### Environment variable, TAIL
Whilst BACKLOG=false restricts the tail by setting the Docker Logs.Options.Since to time.Now(), another mechanism to restrict the tail is to set TAIL=n. Use of this mechanism avoids parsing the earlier content of the logfile which may have a speed advantage if the tail content is of no interest or has become corrupted.

#### Inspect log streams using curl

Using the [httpstream module](http://github.com/gliderlabs/logspout/blob/master/httpstream), you can connect with curl to see your local aggregated logs in realtime. You can do this without setting up a route URI.
Expand Down Expand Up @@ -135,6 +139,7 @@ Logspout relies on the Docker API to retrieve container logs. A failure in the A

* `ALLOW_TTY` - include logs from containers started with `-t` or `--tty` (i.e. `Allocate a pseudo-TTY`)
* `BACKLOG` - suppress container tail backlog
* `TAIL` - specify the number of lines in the log tail to capture when logspout starts (default `all`)
* `DEBUG` - emit debug logs
* `EXCLUDE_LABEL` - exclude logs with a given label
* `INACTIVITY_TIMEOUT` - detect hang in Docker API (default 0)
Expand Down
7 changes: 4 additions & 3 deletions router/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents, backlog bool, inactivityTim
return
}

var tail = getopt("TAIL", "all")
var sinceTime time.Time
if backlog {
sinceTime = time.Unix(0, 0)
Expand All @@ -215,18 +216,18 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents, backlog bool, inactivityTim
p.update(event)
go func() {
for {
debug("pump.pumpLogs():", id, "started")
debug("pump.pumpLogs():", id, "started, tail:", tail)
err := p.client.Logs(docker.LogsOptions{
Container: id,
OutputStream: outwr,
ErrorStream: errwr,
Stdout: true,
Stderr: true,
Follow: true,
Tail: "all",
Tail: tail,
Since: sinceTime.Unix(),
InactivityTimeout: inactivityTimeout,
RawTerminal: allowTTY,
RawTerminal: allowTTY,
})
if err != nil {
debug("pump.pumpLogs():", id, "stopped with error:", err)
Expand Down

0 comments on commit b6a1988

Please sign in to comment.