log

package
v0.0.0-...-26e1b9e Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

Log模块

Log模块封装了zap日志库,简化日志调用。

feature
  • 通过nacos动态调整日志输入最低级别

  • 根据日志大小或者大小动态分割日志

  • 可以保留多个备份

  • 可以以KV形式输出

    使用示例:

func TestFieldContext(t *testing.T) {
	Info("test", FieldContext(context.TODO()))
	s := make(map[string]*string)
	t1 := "33"
	s["a"] = &t1
	Info("111", FieldAny("data", s))
	user := &User{Name: "111", Date: time.Now()}
	Info("2222", FieldAny("user", user))
}

type User struct {
	Name string
	Date time.Time
}

func (u User) String() string {
	return "33333"
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoLevel

func AutoLevel()

func Debug

func Debug(msg interface{}, fields ...Field)

func Debugf

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

func Debugw

func Debugw(msg interface{}, keysAndValues ...interface{})

func Error

func Error(msg interface{}, fields ...Field)

func Errorf

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

func Errorw

func Errorw(msg interface{}, keysAndValues ...interface{})

func Fatal

func Fatal(msg interface{}, fields ...Field)

func Fatalf

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

func Fatalw

func Fatalw(msg interface{}, keysAndValues ...interface{})

func Flush

func Flush() error

func Info

func Info(msg interface{}, fields ...Field)

func Infof

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

func Infow

func Infow(msg interface{}, keysAndValues ...interface{})

func Init

func Init(config *Config)

Init 初始化全局的日志框架

func Panic

func Panic(msg interface{}, fields ...Field)

func Panicf

func Panicf(template string, args ...interface{})

func Panicw

func Panicw(msg interface{}, keysAndValues ...interface{})

func Warn

func Warn(msg interface{}, fields ...Field)

func Warnf

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

func Warnw

func Warnw(msg interface{}, keysAndValues ...interface{})

Types

type Config

type Config struct {
	FileName      string `json:"fileName" yaml:"fileName"`           // 全路径文件名
	DisableCaller bool   `json:"disableCaller" yaml:"disableCaller"` // 是否添加调用者信息
	MaxSize       int    `json:"maxSize" yaml:"maxSize"`             // 日志输出文件最大长度,超过改值则截断
	MaxAge        int    `json:"maxAge" yaml:"maxAge"`               // 文件最多保存多少天
	MaxBackup     int    `json:"maxBackup" yaml:"maxBackup"`         // 日志文件最多保存多少个备份
	CallerSkip    int    `json:"callerSkip" yaml:"callerSkip"`       // CallerSkip
	Debug         bool   `json:"debug" yaml:"debug"`                 // 是否打印日志到控制台
	Level         string `json:"level" yaml:"level"`                 // 日志打印级别
	Compress      bool   `json:"compress" yaml:"compress"`           // 是否压缩
}

Config 日志配置

func DefaultConfig

func DefaultConfig() Config

type Field

type Field = zap.Field

func FieldAddr

func FieldAddr(value string) Field

func FieldAny

func FieldAny(key string, object interface{}) Field

func FieldContext

func FieldContext(ctx context.Context) Field

func FieldCost

func FieldCost(value time.Duration) Field

func FieldErr

func FieldErr(err error) Field

func FieldMethod

func FieldMethod(value string) Field

func FieldMod

func FieldMod(value string) Field

type Logger

type Logger struct {
	// contains filtered or unexported fields
}
var (
	LLogger *Logger
)

func GetLogger

func GetLogger() *Logger

Jump to

Keyboard shortcuts

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