Documentation
¶
Index ¶
- Constants
- func CopyDockerLogs(stdout, stderr io.Writer, src io.Reader) (int64, error)
- func SanitizeLogMessage(msg string) string
- type Config
- type ContainerLogStream
- type DockerLogLine
- type LogClientResolver
- type LogStreamer
- func (ls *LogStreamer) AddCommandEntry(containerID, command string, timestamp time.Time)
- func (ls *LogStreamer) AddCommandOutput(containerID, output string, success bool, timestamp time.Time)
- func (ls *LogStreamer) CleanupContainer(containerID string)
- func (ls *LogStreamer) ClearLogs(containerID string)
- func (ls *LogStreamer) GetLogs(containerID string, tail int) []*v1.LogEntry
- func (ls *LogStreamer) MigrateSubscribers(oldContainerID, newContainerID string)
- func (ls *LogStreamer) RemoveContainer(containerID string)
- func (ls *LogStreamer) RemoveStream(containerID string)
- func (ls *LogStreamer) SetClientResolver(r LogClientResolver)
- func (ls *LogStreamer) StartStreaming(containerID string) error
- func (ls *LogStreamer) StopStreaming(containerID string)
- func (ls *LogStreamer) Subscribe(containerID string) chan *v1.LogEntry
- func (ls *LogStreamer) Unsubscribe(containerID string, ch chan *v1.LogEntry)
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Debug(format string, args ...any)
- func (l *Logger) Error(format string, args ...any)
- func (l *Logger) Fatal(format string, args ...any)
- func (l *Logger) GetLogFilePath() string
- func (l *Logger) GetRecentLogs() []string
- func (l *Logger) GetRecentLogsSince(since time.Duration) []string
- func (l *Logger) Info(format string, args ...any)
- func (l *Logger) SetBufferTTL(ttl time.Duration)
- func (l *Logger) Warn(format string, args ...any)
Constants ¶
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
CopyDockerLogs demultiplexes a non-TTY Docker log stream. stdout and stderr are separate writers. The signature has no protobuf type.
func SanitizeLogMessage ¶
SanitizeLogMessage scrubs sensitive passwords and tokens from log messages (SEC-4)
Types ¶
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
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 ¶
func NewWithConfig ¶
func (*Logger) GetLogFilePath ¶
GetLogFilePath returns current log file path
func (*Logger) GetRecentLogs ¶
GetRecentLogs returns all currently unexpired log lines from memory buffer.
func (*Logger) GetRecentLogsSince ¶
GetRecentLogsSince returns unexpired buffered logs newer than the specified relative duration.
func (*Logger) SetBufferTTL ¶
SetBufferTTL configures the retention TTL for buffered in-memory logs.