logger

package
v0.0.0-...-fc09d8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package logger provides shim loggers for Containerd.

Index

Constants

View Source
const (
	// DaemonName represents the name of the shim logger daemon for containerd.
	DaemonName = "shim-loggers-for-containerd"
	// NonBlockingMode indicates the mode of logger which doesn't block on logging.
	NonBlockingMode = "non-blocking"

	// DefaultBufSizeInBytes provides a reasonable default for loggers that do
	// not have an external limit to impose on log line size. Adopted this value
	// from Docker, reference:
	// https://github.com/moby/moby/blob/19.03/daemon/logger/copier.go#L21
	DefaultBufSizeInBytes = 16 * 1024
)

Variables

This section is empty.

Functions

func NewInfo

func NewInfo(containerID string, containerName string, options ...InfoOpt) *dockerlogger.Info

NewInfo creates the placeholder info. Expected that relevant parts will be modified via the common_opts.

func SetUIDAndGID

func SetUIDAndGID(uid int, gid int) error

SetUIDAndGID sets UID and/or GID for current goroutine/process. If you are building with go version includes the following commit, you only need to call this once. Otherwise you need call this function in all goroutines. Commit: https://github.com/golang/go/commit/d1b1145cace8b968307f9311ff611e4bb810710c TODO: remove the above comment once the changes are released: https://go-review.googlesource.com/c/go/+/210639

func UpdateDockerConfigs

func UpdateDockerConfigs(info *dockerlogger.Info, dockerConfigs *DockerConfigs) *dockerlogger.Info

UpdateDockerConfigs updates the docker config fields to the logger info.

Types

type Client

type Client interface {
	Log(*dockerlogger.Message) error
}

Client is a wrapper for docker logger's Log method, which is mostly used for testing purposes.

type DockerConfigs

type DockerConfigs struct {
	// ContainerImageID is the ID of the container image.
	ContainerImageID string
	// ContainerImageName is the name of the container image.
	ContainerImageName string
	// ContainerEnv contains environment variables of the container.
	ContainerEnv []string
	// ContainerLabels holds labels associated with the container.
	ContainerLabels map[string]string
}

DockerConfigs holds optional Docker configuration details.

type GlobalArgs

type GlobalArgs struct {
	// Required arguments
	ContainerID   string
	ContainerName string
	LogDriver     string

	// Optional arguments
	Mode          string
	MaxBufferSize int
	UID           int
	GID           int
	CleanupTime   *time.Duration
}

GlobalArgs contains the essential arguments required for initializing the logger.

type InfoOpt

type InfoOpt func(*dockerlogger.Info)

InfoOpt is a type of function that is used to update the values of fields in logger info for each driver. Field supported to be modified is config.

func WithConfig

func WithConfig(m map[string]string) InfoOpt

WithConfig sets logger config of logger info.

type LogDriver

type LogDriver interface {
	// Start functions starts sending container logs to destination.
	Start(context.Context, *time.Duration, func() error) error
	// GetPipes gets pipes of container that exposed by containerd.
	GetPipes() (map[string]io.Reader, error)
	// Log sends logs to destination.
	Log(*dockerlogger.Message) error
	// Read reads a single log message from container pipe and sends it to
	// destination or saves it to ring buffer, depending on the mode of log
	// driver.
	Read(context.Context, io.Reader, string, int, sendLogToDestFunc) error
}

LogDriver is the interface for all log drivers.

func NewBufferedLogger

func NewBufferedLogger(l LogDriver, bufferReadSize int, maxBufferSize int, containerID string) LogDriver

NewBufferedLogger creates a logger with the provided LoggerOpt, a buffer with customized max size and a channel monitor if stdout and stderr pipes are closed.

func NewLogger

func NewLogger(options ...Opt) (LogDriver, error)

NewLogger creates a LogDriver with the provided LoggerOpt.

type Logger

type Logger struct {
	Info   *dockerlogger.Info
	Stream Client
	Stdout io.Reader
	Stderr io.Reader
	// contains filtered or unexported fields
}

Logger is the basic struct for all log drivers.

func (*Logger) GetPipes

func (l *Logger) GetPipes() (map[string]io.Reader, error)

GetPipes gets pipes of container and its name that exposed by containerd.

func (*Logger) Log

func (l *Logger) Log(message *dockerlogger.Message) error

Log sends logs to destination.

func (*Logger) Read

func (l *Logger) Read(
	ctx context.Context,
	pipe io.Reader,
	source string,
	bufferSizeInBytes int,
	sendLogMsgToDest sendLogToDestFunc,
) error

Read gets container logs, saves them to our own buffer. Then we will read logs line by line and send them to destination. In non-blocking mode, the destination is the ring buffer. More log messages will be sent in verbose mode for debugging.

func (*Logger) Start

func (l *Logger) Start(
	ctx context.Context,
	cleanupTime *time.Duration,
	ready func() error,
) error

Start starts the actual logger.

type Opt

type Opt func(*Logger)

Opt is a type of function that is used to update the values of fields in LoggerArgs. Fields supported to be modified are logger info, stdout and stderr.

func WithBufferSizeInBytes

func WithBufferSizeInBytes(size int) Opt

WithBufferSizeInBytes sets the buffer size of log driver.

func WithInfo

func WithInfo(info *dockerlogger.Info) Opt

WithInfo sets log driver's info.

func WithMaxReadBytes

func WithMaxReadBytes(size int) Opt

WithMaxReadBytes sets how many bytes will be read from container pipe per iteration.

func WithStderr

func WithStderr(stderr io.Reader) Opt

WithStderr sets log driver's stderr pipe.

func WithStdout

func WithStdout(stdout io.Reader) Opt

WithStdout sets log driver's stdout pipe.

func WithStream

func WithStream(stream Client) Opt

WithStream sets the actual stream of log driver.

type WindowsArgs

type WindowsArgs struct {
	ProxyEnvVar string
	LogFileDir  string
}

WindowsArgs struct for Windows configuration.

Directories

Path Synopsis
Package awslogs provides functionalities for integrating the awslogs logging driver with shim-loggers-for-containerd.
Package awslogs provides functionalities for integrating the awslogs logging driver with shim-loggers-for-containerd.
Package fluentd provides functionalities for integrating the fluentd logging driver with shim-loggers-for-containerd.
Package fluentd provides functionalities for integrating the fluentd logging driver with shim-loggers-for-containerd.
Package mock_logger is a generated GoMock package.
Package mock_logger is a generated GoMock package.
Package splunk provides functionalities for integrating the splunk logging driver with shim-loggers-for-containerd.
Package splunk provides functionalities for integrating the splunk logging driver with shim-loggers-for-containerd.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL