podman
58 строк · 1.6 Кб
1package docker2
3import (4"context"5"io"6"net/http"7"time"8)
9
10// LogsOptions represents the set of options used when getting logs from a
11// container.
12//
13// See https://goo.gl/krK0ZH for more details.
14type LogsOptions struct {15Context context.Context16Container string `qs:"-"`17OutputStream io.Writer `qs:"-"`18ErrorStream io.Writer `qs:"-"`19InactivityTimeout time.Duration `qs:"-"`20Tail string21
22Since int6423Follow bool24Stdout bool25Stderr bool26Timestamps bool27
28// Use raw terminal? Usually true when the container contains a TTY.29RawTerminal bool `qs:"-"`30}
31
32// Logs gets stdout and stderr logs from the specified container.
33//
34// When LogsOptions.RawTerminal is set to false, go-dockerclient will multiplex
35// the streams and send the containers stdout to LogsOptions.OutputStream, and
36// stderr to LogsOptions.ErrorStream.
37//
38// When LogsOptions.RawTerminal is true, callers will get the raw stream on
39// LogsOptions.OutputStream. The caller can use libraries such as dlog
40// (github.com/ahmetalpbalkan/dlog).
41//
42// See https://goo.gl/krK0ZH for more details.
43func (c *Client) Logs(opts LogsOptions) error {44if opts.Container == "" {45return &NoSuchContainer{ID: opts.Container}46}47if opts.Tail == "" {48opts.Tail = "all"49}50path := "/containers/" + opts.Container + "/logs?" + queryString(opts)51return c.stream(http.MethodGet, path, streamOptions{52setRawTerminal: opts.RawTerminal,53stdout: opts.OutputStream,54stderr: opts.ErrorStream,55inactivityTimeout: opts.InactivityTimeout,56context: opts.Context,57})58}
59