logger

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxBuffer is the maximum number of recent log lines retained in memory.
	DefaultMaxBuffer = 1000
	// DefaultBufferTTL is the maximum age of log lines kept in memory buffer.
	DefaultBufferTTL = 24 * time.Hour
)

Variables

This section is empty.

Functions

func CopyDockerLogs added in v1.0.39

func CopyDockerLogs(stdout, stderr io.Writer, src io.Reader) (int64, error)

CopyDockerLogs demultiplexes a non-TTY Docker log stream. stdout and stderr are separate writers. The signature has no protobuf type.

func SanitizeLogMessage

func SanitizeLogMessage(msg string) string

SanitizeLogMessage scrubs sensitive passwords and tokens from log messages (SEC-4)

Types

type Config

type Config struct {
	Enabled    bool
	FilePath   string
	MaxSize    int
	MaxBackups int
	MaxAge     int
	Compress   bool
	MaxBuffer  int
	BufferTTL  time.Duration
}

type ContainerLogStream

type ContainerLogStream struct {
	// contains filtered or unexported fields
}

ContainerLogStream manages log streaming for a single container

type DockerLogLine added in v1.0.39

type DockerLogLine struct {
	Stream string
	Text   string
}

DockerLogLine is one line from a non-TTY Docker log stream. Stream is "stdout" or "stderr".

func ReadDockerLogLines added in v1.0.39

func ReadDockerLogLines(src io.Reader) ([]DockerLogLine, error)

ReadDockerLogLines reads a complete non-TTY Docker log stream into lines.

type LogClientResolver

type LogClientResolver interface {
	ResolveLogClient(ctx context.Context, containerID string) (*client.Client, error)
}

LogClientResolver resolves the Docker SDK client responsible for a container. It lets the streamer tail containers on non-local nodes (MINE-108). Returning (nil, nil) means "unknown — fall back to the local client".

type LogStreamer

type LogStreamer struct {
	// contains filtered or unexported fields
}

LogStreamer manages log streaming for all containers

func NewLogStreamer

func NewLogStreamer(dockerClient *client.Client, log *Logger, maxEntriesPerContainer int) *LogStreamer

NewLogStreamer creates a new log streamer

func (*LogStreamer) AddCommandEntry

func (ls *LogStreamer) AddCommandEntry(containerID, command string, timestamp time.Time)

AddCommandEntry prepends command execution with command input log

func (*LogStreamer) AddCommandOutput

func (ls *LogStreamer) AddCommandOutput(containerID, output string, success bool, timestamp time.Time)

AddCommandOutput adds command output to the log stream (after execution)

func (*LogStreamer) CleanupContainer

func (ls *LogStreamer) CleanupContainer(containerID string)

CleanupContainer removes all log resources associated with a container

func (*LogStreamer) ClearLogs

func (ls *LogStreamer) ClearLogs(containerID string)

ClearLogs clears logs for a container

func (*LogStreamer) GetLogs

func (ls *LogStreamer) GetLogs(containerID string, tail int) []*v1.LogEntry

GetLogs gets logs for a container

func (*LogStreamer) MigrateSubscribers

func (ls *LogStreamer) MigrateSubscribers(oldContainerID, newContainerID string)

Move all subscribers from old container to new container, recording an alias so a later Unsubscribe against oldContainerID still resolves correctly.

func (*LogStreamer) RemoveContainer

func (ls *LogStreamer) RemoveContainer(containerID string)

RemoveContainer stops streaming, frees log buffers, and cleans up subscribers for a container

func (*LogStreamer) RemoveStream

func (ls *LogStreamer) RemoveStream(containerID string)

RemoveStream removes a container's log stream and cleans up its resources

func (*LogStreamer) SetClientResolver

func (ls *LogStreamer) SetClientResolver(r LogClientResolver)

SetClientResolver installs a resolver that lets the streamer target containers on remote nodes instead of always inspecting/tailing the local daemon.

func (*LogStreamer) StartStreaming

func (ls *LogStreamer) StartStreaming(containerID string) error

StartStreaming starts streaming logs for a container

func (*LogStreamer) StopStreaming

func (ls *LogStreamer) StopStreaming(containerID string)

StopStreaming stops streaming logs for a container and frees its log buffer

func (*LogStreamer) Subscribe

func (ls *LogStreamer) Subscribe(containerID string) chan *v1.LogEntry

Subscribe creates a channel that receives new log entries for a container

func (*LogStreamer) Unsubscribe

func (ls *LogStreamer) Unsubscribe(containerID string, ch chan *v1.LogEntry)

Unsubscribe removes a subscriber channel for a container.

The containerID may be one the channel was originally registered under and has since been migrated away from (see MigrateSubscribers); the alias chain is followed so the channel is found and closed rather than silently leaked.

type Logger

type Logger struct {
	*log.Logger
	// contains filtered or unexported fields
}

func New

func New() *Logger

func NewWithConfig

func NewWithConfig(cfg *Config) *Logger

func (*Logger) Close

func (l *Logger) Close() error

Close file logger

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...any)

func (*Logger) Error

func (l *Logger) Error(format string, args ...any)

func (*Logger) Fatal

func (l *Logger) Fatal(format string, args ...any)

func (*Logger) GetLogFilePath

func (l *Logger) GetLogFilePath() string

GetLogFilePath returns current log file path

func (*Logger) GetRecentLogs

func (l *Logger) GetRecentLogs() []string

GetRecentLogs returns all currently unexpired log lines from memory buffer.

func (*Logger) GetRecentLogsSince

func (l *Logger) GetRecentLogsSince(since time.Duration) []string

GetRecentLogsSince returns unexpired buffered logs newer than the specified relative duration.

func (*Logger) Info

func (l *Logger) Info(format string, args ...any)

func (*Logger) SetBufferTTL

func (l *Logger) SetBufferTTL(ttl time.Duration)

SetBufferTTL configures the retention TTL for buffered in-memory logs.

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...any)

Jump to

Keyboard shortcuts

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