package buffer

import "k8s.io/klog/v2/internal/buffer"

Package buffer provides a cache for byte.Buffer instances that can be reused to avoid frequent allocation and deallocation. It also has utility code for log header formatting that use these buffers.

Index

Variables

var (
	// Pid is inserted into log headers. Can be overridden for tests.
	Pid = os.Getpid()
)

Types

type Buffer

type Buffer struct {
	bytes.Buffer
	Tmp [64]byte // temporary byte array for creating headers.
	// contains filtered or unexported fields
}

Buffer holds a single byte.Buffer for reuse. The zero value is ready for use. It also provides some helper methods for output formatting.

func (*Buffer) FormatHeader

func (buf *Buffer) FormatHeader(s severity.Severity, file string, line int, now time.Time)

FormatHeader formats a log header using the provided file name and line number.

type Buffers

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

Buffers manages the reuse of individual buffer instances. It is thread-safe.

func (*Buffers) GetBuffer

func (bl *Buffers) GetBuffer() *Buffer

GetBuffer returns a new, ready-to-use buffer.

func (*Buffers) PutBuffer

func (bl *Buffers) PutBuffer(b *Buffer)

PutBuffer returns a buffer to the free list.

Source Files

buffer.go

Version
v2.50.1
Published
Mar 16, 2022
Platform
darwin/amd64
Imports
5 packages
Last checked
37 minutes ago

Tools for package owners.