buffer

package
v2.120.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

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

	// Time, if set, will be used instead of the actual current time.
	Time *time.Time
)

Functions

func PutBuffer added in v2.90.0

func PutBuffer(b *Buffer)

PutBuffer returns a buffer to the free list.

Types

type Buffer

type Buffer struct {
	bytes.Buffer
	Tmp [64]byte // temporary byte array for creating headers.
}

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 GetBuffer added in v2.90.0

func GetBuffer() *Buffer

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

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 and writes it into the buffer.

func (*Buffer) SprintHeader added in v2.90.1

func (buf *Buffer) SprintHeader(s severity.Severity, now time.Time) string

SprintHeader formats a log header and returns a string. This is a simpler version of FormatHeader for use in ktesting.

Jump to

Keyboard shortcuts

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