Example #1
0
func (i *Input) processLogs(job Job, o io.Output) {
	opts := dockerclient.LogOptions{
		Stdout: job.Stdout,
		Stderr: job.Stderr,
		Follow: true,
		Tail:   0,
	}
	init := true

	for {
		if info, err := i.client.InspectContainer(job.Id); err == nil {
			tags := i.tags(job, info)

			if init || info.State.Running {
				if s, err := i.client.ContainerLogs(job.Id, &opts); err == nil {
					scanner := bufio.NewScanner(Demuxer(s))
					for scanner.Scan() {
						if doc, err := io.Encode(scanner.Text(), tags); err == nil {
							o.Push(doc)
						}
					}
					init = false
					opts.Tail = 1 // FIXME: Not accurate!
				}
			}
		} else {
			break
		}

		time.Sleep(time.Second * 3)
	}

	i.done <- job
}
Example #2
0
// Listen for incoming documents and process them.
func (s *Input) Listen(o io.Output) {
	tags := map[string]interface{}{"type": "stdin"}
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		if doc, err := io.Encode(scanner.Text(), tags); err == nil {
			o.Push(doc)
		}
	}
}