logx

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//level
	ERROR = "error"
	DEBUG = "debug"
	PANIC = "panic"
	INFO  = "info"
	WARN  = "warn"

	//输出类型
	JSON = "json"
	TXT  = "txt"

	//输出位置
	CONSOLE = "console"
	FILE    = "file"
	ALL     = "all"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Logx

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

func NewLogx

func NewLogx(cfg LogxConfig) (*Logx, error)

type LogxConfig

type LogxConfig struct {
	//分割配置
	LogName      string `default:"log.log"` // 日志文件路径,默认 os.TempDir()
	MaxSize      int    `default:"10"`      // 每个日志文件保存10M,默认 100M
	MaxBackNum   int    `default:"15" `     // 保留30个备份,默认不限
	MaxAge       int    `default:"7"`       // 保留7天,默认不限
	Compress     bool   `default:"false"`   // 是否压缩,默认不压缩
	Level        string `default:"debug" validate:"one_of=error,debug,panic,info,warn"`
	OutType      string `default:"console" validate:"one_of=console,file,all"` // 输出到哪 console all file
	Formatter    string `default:"txt" validate:"one_of=txt,json"`             //json or txt
	HasTimestamp bool   `default:"false"`
	Caller       bool   `default:"false"` //启用堆栈
	Development  bool   `default:"false"` // 记录行号
}

生成log

type LogxOpt

type LogxOpt func(*LogxConfig)

func WithBackNum

func WithBackNum(num int) LogxOpt

设置备份数量

func WithCaller

func WithCaller(has bool) LogxOpt

func WithCompress

func WithCompress(cpr bool) LogxOpt

设置是否压缩

func WithDev

func WithDev(has bool) LogxOpt

func WithFileName

func WithFileName(name string) LogxOpt

func WithFormatter

func WithFormatter(formatter string) LogxOpt

func WithLevel

func WithLevel(level string) LogxOpt

func WithMaxAge

func WithMaxAge(day int) LogxOpt

设置保留天数

func WithMaxSize

func WithMaxSize(size int) LogxOpt

设置最大文件尺寸

func WithOutType

func WithOutType(tp string) LogxOpt

Jump to

Keyboard shortcuts

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