logger

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context) *zap.Logger

Get extracts a logger from the context. If no logger is found in the context, it returns the default logger. This function is safe to call with a nil context.

func NewZapLoggingModule

func NewZapLoggingModule() fx.Option

NewZapLoggingModule creates a new fx module for zap logger initialization. It provides a configured *zap.Logger instance and integrates with fx lifecycle.

func With

func With(ctx context.Context, logger *zap.Logger) context.Context

With returns a new context with the provided logger attached. This allows propagating logger instances through the application context.

Types

type Config

type Config struct {
	// Level specifies the minimum logging level.
	// Use zapcore constants: DebugLevel, InfoLevel, WarnLevel, ErrorLevel, DPanicLevel, PanicLevel, FatalLevel
	Level zapcore.Level

	// Development enables development mode with console encoding and human-readable timestamps.
	// In production mode (false), JSON encoding is used.
	Development bool

	// StacktraceLevel sets the minimum level at which stacktraces are captured.
	// Use zapcore constants: DebugLevel, InfoLevel, WarnLevel, ErrorLevel, DPanicLevel, PanicLevel, FatalLevel
	// Defaults to ErrorLevel.
	StacktraceLevel zapcore.Level
}

type LogThrottler

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

LogThrottler provides rate-limited logging functionality. Each instance maintains its own isolated map of rate limiters, allowing different components to have independent throttling.

func NewLogThrottler

func NewLogThrottler(log *zap.Logger, interval time.Duration) *LogThrottler

NewLogThrottler creates a new LogThrottler with the given logger. The interval parameter specifies how often a WARN log is allowed per key. If interval is 0, it defaults to 5 minutes.

func (*LogThrottler) Warn

func (t *LogThrottler) Warn(key string, msg string, fields ...zap.Field)

Warn logs as WARN once per interval per key, DEBUG otherwise. This is useful for suppressing repetitive error logs while still maintaining visibility of ongoing issues.

Jump to

Keyboard shortcuts

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