log

package
v0.0.0-...-a253b9f Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Levels = map[string]zapcore.Level{
	"":      zapcore.DebugLevel,
	"debug": zapcore.DebugLevel,
	"info":  zapcore.InfoLevel,
	"warn":  zapcore.WarnLevel,
	"error": zapcore.ErrorLevel,
	"fatal": zapcore.FatalLevel,
}

Levels zap日志级别映射表

Functions

func CustomTimeFormat

func CustomTimeFormat(t time.Time, format string) string

CustomTimeFormat 自定义时间格式

func Debug

func Debug(args ...interface{})

Debug 日志

func Debugf

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

Debugf printf风格的日志

func DefaultTimeFormat

func DefaultTimeFormat(t time.Time) []byte

DefaultTimeFormat 默认时间格式

func Error

func Error(args ...interface{})

Error 日志

func Errorf

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

Errorf printf风格的日志

func Fatal

func Fatal(args ...interface{})

Fatal 日志

func Fatalf

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

Fatalf printf风格的日志

func GetLogger

func GetLogger() *zap.SugaredLogger

GetLogger 获取logger

func Info

func Info(args ...interface{})

Info 日志

func Infof

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

Infof printf风格的日志

func InitLogger

func InitLogger(opc []OutputConfig)

InitLogger 初始化日志组件

func NewTimeEncoder

func NewTimeEncoder(format string) zapcore.TimeEncoder

NewTimeEncoder 创建时间格式encoder

func Warn

func Warn(args ...interface{})

Warn 日志

func Warnf

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

Warnf printf风格的日志

Types

type FormatConfig

type FormatConfig struct {
	// TimeFmt 日志输出时间格式,空默认为"2006-01-02 15:04:05.000"
	TimeFmt string `yaml:"time_fmt"`
	// TimeKey 日志输出时间key, 默认为"Timestamp"
	TimeKey string `yaml:"time_key"`
	// LevelKey 日志级别输出key, 默认为"Level"
	LevelKey string `yaml:"level_key"`
	// NameKey 日志名称key, 默认为"Name"
	NameKey string `yaml:"name_key"`
	// CallerKey 日志输出调用者key, 默认"Caller"
	CallerKey string `yaml:"caller_key"`
	// FunctionKey 日志输出调用者函数名, 默认"",表示不打印函数名
	FunctionKey string `yaml:"function_key"`
	// MessageKey 日志输出消息体key,默认"Message"
	MessageKey string `yaml:"message_key"`
	// StacktraceKey 日志输出堆栈trace key, 默认"Stacktrace"
	StacktraceKey string `yaml:"stacktrace_key"`
}

FormatConfig Formater配置

type OutputConfig

type OutputConfig struct {
	// 日志输出端 (file,console)
	Writer      string      `yaml:"writer"`
	WriteConfig WriteConfig `yaml:"write_config"`
	// 日志输出格式 (console, json)
	Formatter    string       `yaml:"formatter"`
	FormatConfig FormatConfig `yaml:"format_config"`
	Level        string       `yaml:"level"`
}

OutputConfig 日志配置结构体

type Wrapper

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

Wrapper 代理logger,使得With与Debug等日志调用栈层数一致

func WithField

func WithField(fields ...interface{}) *Wrapper

WithField 设置数据字典

func (*Wrapper) Debug

func (w *Wrapper) Debug(args ...interface{})

Debug 日志

func (*Wrapper) Debugf

func (w *Wrapper) Debugf(format string, args ...interface{})

Debugf printf风格的日志

func (*Wrapper) Error

func (w *Wrapper) Error(args ...interface{})

Error 日志

func (*Wrapper) Errorf

func (w *Wrapper) Errorf(format string, args ...interface{})

Errorf printf风格的日志

func (*Wrapper) Fatal

func (w *Wrapper) Fatal(args ...interface{})

Fatal 日志

func (*Wrapper) Fatalf

func (w *Wrapper) Fatalf(format string, args ...interface{})

Fatalf printf风格的日志

func (*Wrapper) Info

func (w *Wrapper) Info(args ...interface{})

func (*Wrapper) Infof

func (w *Wrapper) Infof(format string, args ...interface{})

Infof printf风格的日志

func (*Wrapper) Warn

func (w *Wrapper) Warn(args ...interface{})

Warn 日志

func (*Wrapper) Warnf

func (w *Wrapper) Warnf(format string, args ...interface{})

Warnf printf风格的日志

type WriteConfig

type WriteConfig struct {
	// 文件日志路径(含文件名)
	LogPath string `yaml:"log_path"`
	// 日志最大大小 单位(MB)
	MaxSize int `yaml:"max_size"`
	// 日志最大保留时间,单位(天)
	MaxAge int `yaml:"max_age"`
	// 日志最大保留文件数
	MaxBackups int `yaml:"max_backups"`
	// 是否启用压缩
	Compress bool `yaml:"compress"`
}

WriteConfig Writer配置

Jump to

Keyboard shortcuts

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