logx

package
v0.0.0-...-61a7dbd Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ZapFormatJson = "json"
	ZapFormatText = "text"

	ZapEncodeLevelLower      = "lower"
	ZapEncodeLevelLowerColor = "lowerColor"
	ZapEncodeLevelCap        = "cap"
	ZapEncodeLevelCapColor   = "capColor"
)
View Source
const LoggerKey = "zapLogger"

Variables

View Source
var Default = NewLog(&Zap{Director: "logs"})
View Source
var FileRotatelogs = new(fileRotatelogs)

Functions

func PathExists

func PathExists(path string) (bool, error)

PathExists 文件是否存在

Types

type Logger

type Logger struct {
	*zap.SugaredLogger
}

func NewLog

func NewLog(c *Zap) *Logger

NewLog 获取 zap.Logger

func (*Logger) NewContext

func (l *Logger) NewContext(ctx *gin.Context, fields ...any)

NewContext 给指定的context添加字段

func (*Logger) WithContext

func (l *Logger) WithContext(ctx *gin.Context) *Logger

WithContext 从指定的context返回一个zap实例

type Zap

type Zap struct {
	Level         string `mapstructure:"level" yaml:"level"`                   // 级别
	Prefix        string `mapstructure:"prefix" yaml:"prefix"`                 // 日志前缀
	Format        string `mapstructure:"format" yaml:"format"`                 // 输出,json或text
	Director      string `mapstructure:"director" yaml:"director"`             // 日志文件夹
	EncodeLevel   string `mapstructure:"encode-level" yaml:"encode-level"`     // 编码级
	StacktraceKey string `mapstructure:"stacktrace-key" yaml:"stacktrace-key"` // 栈名
	MaxAge        int    `mapstructure:"max-age" yaml:"max-age"`               // 日志留存时间
	ShowLine      bool   `mapstructure:"show-line" yaml:"show-line"`           // 显示行
	LogInConsole  bool   `mapstructure:"log-in-console" yaml:"log-in-console"` // 输出控制台
}

func (*Zap) TransportLevel

func (z *Zap) TransportLevel() zapcore.Level

TransportLevel 根据字符串转化为 zapcore.Level

func (*Zap) ZapEncodeLevel

func (z *Zap) ZapEncodeLevel() zapcore.LevelEncoder

ZapEncodeLevel 根据 EncodeLevel 返回 zapcore.LevelEncoder

Jump to

Keyboard shortcuts

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