log

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Logger is a shared go-kit logger.
	// TODO: Change all components to take a non-global logger via their constructors.
	// Prefer accepting a non-global logger as an argument.
	Logger = log.NewNopLogger()
)

Functions

func CheckFatal

func CheckFatal(location string, err error, logger log.Logger)

CheckFatal prints an error and exits with error code 1 if err is non-nil.

func Flush

func Flush() error

func InitLogger

func InitLogger(cfg *server.Config, reg prometheus.Registerer, buffered bool, sync bool)

InitLogger initialises the global gokit logger (util_log.Logger) and overrides the default logger for the server.

func LevelHandler

func LevelHandler(currentLogLevel *logging.Level) http.HandlerFunc

LevelHandler returns an http handler function that returns the current log level. The optional query parameter 'log_level' can be passed to change the log level at runtime.

func WarnExperimentalUse

func WarnExperimentalUse(feature string, logger log.Logger)

WarnExperimentalUse logs a warning and increments the experimental features metric.

func WithContext

func WithContext(ctx context.Context, l log.Logger) log.Logger

WithContext returns a log.Logger that has information about the current user in its details.

e.g.

log := util.WithContext(ctx)
log.Errorf("Could not chunk chunks: %v", err)

func WithUserID

func WithUserID(userID string, l log.Logger) log.Logger

WithUserID returns a Logger that has information about the current user in its details.

Types

type Flusher

type Flusher interface {
	Flush() error
}

type LineBufferedLogger

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

LineBufferedLogger buffers log lines to be flushed periodically. Without a line buffer, Log() will call the write syscall for every log line which is expensive if logging thousands of lines per second.

func NewLineBufferedLogger

func NewLineBufferedLogger(w io.Writer, cap uint32, opts ...LineBufferedLoggerOption) *LineBufferedLogger

NewLineBufferedLogger creates a new LineBufferedLogger with a configured capacity. Lines are flushed when the context is done, the buffer is full, or the flush period is reached.

func (*LineBufferedLogger) Flush

func (l *LineBufferedLogger) Flush() error

Flush forces the buffer to be written to the underlying writer.

func (*LineBufferedLogger) Size

func (l *LineBufferedLogger) Size() uint32

Size returns the number of entries in the buffer.

func (*LineBufferedLogger) Write

func (l *LineBufferedLogger) Write(p []byte) (n int, err error)

Write writes the given bytes to the line buffer, and increments the entries counter. If the buffer is full (entries == cap), it will be flushed, and the entries counter reset.

type LineBufferedLoggerOption

type LineBufferedLoggerOption func(*LineBufferedLogger)

func WithFlushCallback

func WithFlushCallback(fn func(entries uint32)) LineBufferedLoggerOption

WithFlushCallback allows for a callback function to be executed when Flush() is called. The length of the buffer at the time of the Flush() will be passed to the function.

func WithFlushPeriod

func WithFlushPeriod(d time.Duration) LineBufferedLoggerOption

WithFlushPeriod creates a new LineBufferedLoggerOption that sets the flush period for the LineBufferedLogger.

func WithPrellocatedBuffer

func WithPrellocatedBuffer(size uint32) LineBufferedLoggerOption

WithPrellocatedBuffer preallocates a buffer to reduce GC cycles and slice resizing.

Jump to

Keyboard shortcuts

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