asynczap

package
v0.0.4-YQ-2323 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package asynczap implements asynchronous core for zap.

By default, zap writes every log line synchronously and without buffering. This behaviour is completely inadequate for high-rate logging.

This implementation of zap.Core moves file write to background goroutine, while carefully monitoring memory consumption.

When background goroutine can't keep up with logging rate, log records are dropped.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Core

type Core struct {
	zapcore.LevelEnabler
	// contains filtered or unexported fields
}

func NewCore

func NewCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler, options Options) *Core

NewCore creates a Core that writes logs to a WriteSyncer.

func (*Core) Check

func (*Core) Stat

func (c *Core) Stat() Stats

func (*Core) Stop

func (c *Core) Stop()

func (*Core) Sync

func (c *Core) Sync() error

func (*Core) With

func (c *Core) With(fields []zap.Field) zapcore.Core

func (*Core) Write

func (c *Core) Write(ent zapcore.Entry, fields []zap.Field) error

type Options

type Options struct {
	// MaxMemoryUsage is maximum amount of memory that will be used by in-flight log records.
	MaxMemoryUsage int

	// WriteBufferSize specifies size of the buffer used for writes to underlying file.
	WriteBufferSize int

	// FlushInterval specifies how often background goroutine would wake up.
	FlushInterval time.Duration
}

type Stats

type Stats struct {
	// Number of records dropped during memory overflow.
	DroppedRecords int

	// Number of errors returned from underlying writer.
	WriteErrors int
}

Jump to

Keyboard shortcuts

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