logger

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logger 提供基于 zap 的全局日志功能

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close 关闭日志器(刷新缓冲区)

func Debug

func Debug(format string, args ...interface{})

Debug 记录调试日志

func Error

func Error(format string, args ...interface{})

Error 记录错误日志

func Fatal

func Fatal(format string, args ...interface{})

Fatal 记录致命错误并退出

func Info

func Info(format string, args ...interface{})

Info 记录信息日志

func Init

func Init(cfg Config) error

Init 初始化全局日志器

func Panic

func Panic(format string, args ...interface{})

Panic 记录 panic 日志

func Print

func Print(args ...interface{})

Print 兼容标准 log

func Printf

func Printf(format string, args ...interface{})

Printf 兼容标准 log(记录 Info 级别)

func Println

func Println(args ...interface{})

Println 兼容标准 log

func SetLevel

func SetLevel(level string)

SetLevel 设置日志级别

func Sync

func Sync() *zap.Logger

Sync 返回底层的 zap.Logger(用于需要结构化日志的场景)

func Warn

func Warn(format string, args ...interface{})

Warn 记录警告日志

Types

type Config

type Config struct {
	// Level 日志级别: debug, info, warn, error
	Level string `json:"level" yaml:"level"`
	// Format 日志格式: text, json
	Format string `json:"format" yaml:"format"`
	// Output 输出目标: stdout, stderr, 或文件路径
	Output string `json:"output" yaml:"output"`
	// Prefix 日志前缀
	Prefix string `json:"prefix" yaml:"prefix"`
	// MaxSize 日志文件最大大小(MB),超过此大小会切割
	MaxSize int `json:"max_size" yaml:"max_size"`
	// MaxBackups 保留的旧日志文件最大数量
	MaxBackups int `json:"max_backups" yaml:"max_backups"`
	// MaxAge 保留旧日志文件的最大天数
	MaxAge int `json:"max_age" yaml:"max_age"`
	// Compress 是否压缩旧日志文件
	Compress bool `json:"compress" yaml:"compress"`
}

Config 日志配置

type Logger

type Logger struct {
	*zap.SugaredLogger
	// contains filtered or unexported fields
}

Logger 日志记录器

func Global

func Global() *Logger

Global 返回全局日志器

func NewLogger

func NewLogger(cfg Config) (*Logger, error)

NewLogger 创建新的日志记录器

func With

func With(fields ...interface{}) *Logger

With 返回带有字段上下文的日志器

Jump to

Keyboard shortcuts

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