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
- func Global() log.Logger
- func NewGoKit(format string) log.Logger
- func NewGoKitWithLevel(lvl Level, format string) log.Logger
- func NewGoKitWithWriter(format string, writer io.Writer) log.Logger
- func NewRateLimitedLogger(logger log.Logger, logsPerSecond float64, logsBurstSize int, ...) log.Logger
- func SetGlobal(logger log.Logger)
- type BufferedLogger
- type BufferedLoggerOption
- type Level
- type RateLimitedLogger
- type Sprintf
Constants ¶
const ( LogfmtFormat = "logfmt" JSONFormat = "json" )
Variables ¶
This section is empty.
Functions ¶
func NewGoKit ¶
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 ¶
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 ¶
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.
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.
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 ¶
Level is a settable identifier for the minimum level a log entry must have.
func (Level) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (*Level) RegisterFlags ¶
RegisterFlags adds the log level flag to the provided flagset.
func (*Level) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type RateLimitedLogger ¶
type RateLimitedLogger struct {
// contains filtered or unexported fields
}
func (*RateLimitedLogger) Log ¶
func (l *RateLimitedLogger) Log(keyvals ...interface{}) error