logger

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug 调试日志

func Error

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

Error 错误日志

func Fatal

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

Fatal 致命错误日志

func Info

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

Info 信息日志

func Init

func Init(level string, development bool) error

Init 初始化日志 (线程安全) 注意:多次调用 Init 只有第一次调用会真正初始化,后续调用会被忽略

func L

func L() *zap.Logger

L 获取 logger (线程安全)

func S

func S() *zap.SugaredLogger

S 获取 sugared logger (线程安全)

func SetLevel added in v0.2.0

func SetLevel(l LogLevel)

SetLevel changes the log level dynamically

func Sync

func Sync() error

Sync 同步日志 (线程安全)

func Warn

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

Warn 警告日志

func With

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

With 创建带字段的 logger

Types

type FieldLogger added in v0.2.0

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

FieldLogger provides structured logging with fields

func Component added in v0.2.0

func Component(name string) *FieldLogger

Component creates a field logger for component tracking

func Module added in v0.2.0

func Module(name string) *FieldLogger

Module creates a field logger with module name

func NewFieldLogger added in v0.2.0

func NewFieldLogger(fields ...zap.Field) *FieldLogger

NewFieldLogger creates a new field logger

func Operation added in v0.2.0

func Operation(name string) *FieldLogger

Operation creates a field logger for operation tracking

func Request added in v0.2.0

func Request(id string) *FieldLogger

Request creates a field logger for request tracking

func (*FieldLogger) Debug added in v0.2.0

func (fl *FieldLogger) Debug(msg string, fields ...zap.Field)

Debug logs at debug level

func (*FieldLogger) Error added in v0.2.0

func (fl *FieldLogger) Error(msg string, fields ...zap.Field)

Error logs at error level

func (*FieldLogger) Fatal added in v0.2.0

func (fl *FieldLogger) Fatal(msg string, fields ...zap.Field)

Fatal logs at fatal level and exits

func (*FieldLogger) Info added in v0.2.0

func (fl *FieldLogger) Info(msg string, fields ...zap.Field)

Info logs at info level

func (*FieldLogger) Warn added in v0.2.0

func (fl *FieldLogger) Warn(msg string, fields ...zap.Field)

Warn logs at warn level

func (*FieldLogger) With added in v0.2.0

func (fl *FieldLogger) With(fields ...zap.Field) *FieldLogger

With creates a child logger with additional fields

type LogLevel added in v0.2.0

type LogLevel int

LogLevel represents log level

const (
	// DebugLevel logs are typically voluminous, and are usually disabled in production
	DebugLevel LogLevel = iota
	// InfoLevel is the default logging priority
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual human review
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly, it shouldn't generate any error-level logs
	ErrorLevel
	// FatalLevel logs. After a fatal log, the application will exit
	FatalLevel
)

func GetLevel added in v0.2.0

func GetLevel() LogLevel

GetLevel gets the current log level

func ParseLevel added in v0.2.0

func ParseLevel(level string) LogLevel

ParseLevel parses a string to a log level

func (LogLevel) String added in v0.2.0

func (l LogLevel) String() string

String returns the string representation of the log level

Jump to

Keyboard shortcuts

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