logger

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: MIT Imports: 16 Imported by: 2

Documentation

Overview

Package logger 处理日志相关逻辑

Index

Constants

This section is empty.

Variables

View Source
var (
	Logger *zap.Logger
	Once   sync.Once
)

Logger 全局 Logger 对象

Functions

func Debug

func Debug(moduleName string, fields ...zap.Field)

Debug 调试日志,详尽的程序日志 调用示例:

logger.Debug("Database", zap.String("sql", sql))

func DebugJSON

func DebugJSON(moduleName, name string, value interface{})

DebugJSON 记录对象类型的 debug 日志,使用 json.Marshal 进行编码。调用示例:

logger.DebugJSON("Auth", "读取登录用户", auth.CurrentUser())

func DebugString

func DebugString(moduleName, name, msg string)

DebugString 记录一条字符串类型的 debug 日志,调用示例:

logger.DebugString("SMS", "短信内容", string(result.RawResponse))

func Dump

func Dump(value interface{}, msg ...string)

Dump 调试专用,不会中断程序,会在终端打印出 warning 消息。 第一个参数会使用 json.Marshal 进行渲染,第二个参数消息(可选)

logger.Dump(user.User{Name:"test"})
logger.Dump(user.User{Name:"test"}, "用户信息")

func Error

func Error(moduleName string, fields ...zap.Field)

Error 错误时记录,不应该中断程序,查看日志时重点关注

func ErrorJSON

func ErrorJSON(moduleName, name string, value interface{})

func ErrorString

func ErrorString(moduleName, name, msg string)

func Fatal

func Fatal(moduleName string, fields ...zap.Field)

Fatal 级别同 Error(), 写完 log 后调用 os.Exit(1) 退出程序

func FatalJSON

func FatalJSON(moduleName, name string, value interface{})

func FatalString

func FatalString(moduleName, name, msg string)

func Info

func Info(moduleName string, fields ...zap.Field)

Info 告知类日志

func InfoJSON

func InfoJSON(moduleName, name string, value interface{})

func InfoString

func InfoString(moduleName, name, msg string)

func InitLogger

func InitLogger(filename string, maxSize, maxBackup, maxAge int, compress bool, logType string, level string)

InitLogger 日志初始化

func LogIf

func LogIf(err error)

LogIf 当 err != nil 时记录 error 等级的日志

func LogInfoIf

func LogInfoIf(err error)

LogInfoIf 当 err != nil 时记录 info 等级的日志

func LogWarnIf

func LogWarnIf(err error)

LogWarnIf 当 err != nil 时记录 warning 等级的日志

func Warn

func Warn(moduleName string, fields ...zap.Field)

Warn 警告类

func WarnJSON

func WarnJSON(moduleName, name string, value interface{})

func WarnString

func WarnString(moduleName, name, msg string)

Types

type GormLogger

type GormLogger struct {
	ZapLogger     *zap.Logger
	SlowThreshold time.Duration
}

func NewGormLogger

func NewGormLogger() GormLogger

NewGormLogger 外部调用。实例化一个 GormLogger 对象,示例:

func (GormLogger) Error

func (l GormLogger) Error(ctx context.Context, str string, args ...interface{})

func (GormLogger) Info

func (l GormLogger) Info(ctx context.Context, str string, args ...interface{})

func (GormLogger) LogMode

func (l GormLogger) LogMode(level gl.LogLevel) gl.Interface

func (GormLogger) Trace

func (l GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (GormLogger) Warn

func (l GormLogger) Warn(ctx context.Context, str string, args ...interface{})

Jump to

Keyboard shortcuts

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