log

package
v0.0.0-...-de40865 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 14 Imported by: 18

Documentation

Overview

Provenance-includes-location: https://github.com/grafana/loki/blob/7c78d7ea44afb420847255f9f5a4f677ad0f47bf/pkg/util/log/line_buffer.go Provenance-includes-location: https://github.com/grafana/mimir/blob/c8b24a462f7e224950409e7e0a4e0a58f3a79599/pkg/util/log/line_buffer.go Provenance-includes-copyright: Grafana Labs

Index

Constants

View Source
const (
	LogfmtFormat = "logfmt"
	JSONFormat   = "json"
)

Variables

This section is empty.

Functions

func Global

func Global() log.Logger

Global returns the global logger.

func NewGoKit

func NewGoKit(format string) log.Logger

NewGoKit creates a new GoKit logger with the given format. If the given format is empty or unknown, logfmt is used. No additional fields nor filters are added to the created logger, and if they are required, the caller is expected to add them.

func NewGoKitWithLevel

func NewGoKitWithLevel(lvl Level, format string) log.Logger

NewGoKitWithLevel creates a new GoKit logger with the given level and format. If the given format is empty or unknown, logfmt is used.

func NewGoKitWithWriter

func NewGoKitWithWriter(format string, writer io.Writer) log.Logger

NewGoKitWithWriter creates a new GoKit logger with the given format and writer. The input writer must be provided, must be thread-safe, and the caller is expected to guarantee these requirements. If the given format is empty or unknown, logfmt is used. No additional fields nor filters are added to the created logger, and if they are required, the caller is expected to add them.

func NewRateLimitedLogger

func NewRateLimitedLogger(logger log.Logger, logsPerSecond float64, logsBurstSize int, registry prometheus.Registerer) log.Logger

NewRateLimitedLogger returns a log.Logger that is limited to the given number of logs per second, with the given burst size.

func SetGlobal

func SetGlobal(logger log.Logger)

SetGlobal sets the global logger.

Types

type BufferedLogger

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

BufferedLogger 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 NewBufferedLogger

func NewBufferedLogger(w io.Writer, cap uint32, opts ...BufferedLoggerOption) *BufferedLogger

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

func (*BufferedLogger) Flush

func (l *BufferedLogger) Flush() error

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

func (*BufferedLogger) Size

func (l *BufferedLogger) Size() uint32

Size returns the number of entries in the buffer.

func (*BufferedLogger) Write

func (l *BufferedLogger) 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 BufferedLoggerOption

type BufferedLoggerOption func(*BufferedLogger)

func WithFlushCallback

func WithFlushCallback(fn func(entries uint32)) BufferedLoggerOption

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) BufferedLoggerOption

WithFlushPeriod creates a new BufferedLoggerOption that sets the flush period for the BufferedLogger.

func WithPrellocatedBuffer

func WithPrellocatedBuffer(size uint32) BufferedLoggerOption

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

type Level

type Level struct {
	Option level.Option
	// contains filtered or unexported fields
}

Level is a settable identifier for the minimum level a log entry must have.

func (Level) MarshalYAML

func (l Level) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler.

func (*Level) RegisterFlags

func (l *Level) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the log level flag to the provided flagset.

func (*Level) Set

func (l *Level) Set(s string) error

Set updates the value of the allowed level. Implments flag.Value.

func (*Level) String

func (l *Level) String() string

func (*Level) UnmarshalYAML

func (l *Level) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

type RateLimitedLogger

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

func (*RateLimitedLogger) Log

func (l *RateLimitedLogger) Log(keyvals ...interface{}) error

type Sprintf

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

func LazySprintf

func LazySprintf(format string, args ...interface{}) *Sprintf

func (*Sprintf) String

func (s *Sprintf) String() string

Jump to

Keyboard shortcuts

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