logger

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, fields ...zap.Field)

Debug logs at DEBUG level on the global logger.

func Error

func Error(msg string, fields ...zap.Field)

Error logs at ERROR level on the global logger.

func Info

func Info(msg string, fields ...zap.Field)

Info logs at INFO level on the global logger.

func Init

func Init(cfg Config) error

Init initializes the global logger. Call once at program startup before any log calls.

func LevelHandler

func LevelHandler() http.Handler

LevelHandler returns an http.Handler that serves the current log level and accepts PUT requests with JSON body {"level":"debug"} to change it at runtime. Mount at an internal route, e.g.: router.PUT("/internal/log/level", gin.WrapH(logger.LevelHandler()))

func SetLevel

func SetLevel(level zapcore.Level)

SetLevel adjusts the global log level at runtime without restarting.

func Warn

func Warn(msg string, fields ...zap.Field)

Warn logs at WARN level on the global logger.

Types

type Config

type Config struct {
	// Level is the minimum log level: "debug", "info", "warn", "error". Default: "info".
	Level string
	// Format is the output format: "json" or "console". Default: "json".
	Format string
	// Sampling enables log sampling when non-nil.
	Sampling *SamplingConfig
	// StacktraceLevel is the level at which stack traces are attached. Default: "error".
	StacktraceLevel string
}

Config controls logger initialization.

type Logger

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

Logger is a thin wrapper around zap.Logger. A Logger created via With() stores fields for deferred resolution so that package-level vars like `var log = logger.With(...)` pick up the real logger even when evaluated before Init().

func With

func With(fields ...zap.Field) *Logger

With returns a deferred child Logger with pre-attached fields (e.g. component name). Safe to call before Init() — the real logger is resolved at log time.

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...zap.Field)

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...zap.Field)

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...zap.Field)

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...zap.Field)

func (*Logger) With

func (l *Logger) With(fields ...zap.Field) *Logger

With returns a child Logger with the given fields pre-attached. The returned Logger is deferred: it resolves against the current globalLogger at log time, so package-level vars are safe to use before Init() is called.

var log = logger.With(zap.String("component", "dingtalk"))

type SamplingConfig

type SamplingConfig struct {
	// Tick is the sampling window. Default: 1s.
	Tick time.Duration
	// Initial is the number of log entries emitted in full per Tick.
	Initial int
	// Thereafter emits one entry per this many after Initial is exhausted.
	Thereafter int
}

SamplingConfig controls high-frequency log noise reduction.

Jump to

Keyboard shortcuts

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