xlog

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: BSD-3-Clause-Clear Imports: 5 Imported by: 0

Documentation

Overview

日志记录模块

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alert added in v0.0.16

func Alert(msg string, err error)

记录详情日志

msg	消息备注
err	错误详情

func AlertError added in v0.1.1

func AlertError(msg string, err error) error

记录详情日志

msg	消息备注
err	错误详情

func Crit added in v0.0.16

func Crit(msg string, err error)

记录详情日志

msg	消息备注
err	错误详情

func CritError added in v0.1.1

func CritError(msg string, err error) error

记录详情日志

msg	消息备注
err	错误详情

func Debug added in v0.0.16

func Debug(msg string, err error)

记录详情日志

msg	消息备注
err	错误详情

func DebugError added in v0.1.1

func DebugError(msg string, err error) error

记录详情日志

msg	消息备注
err	错误详情

func Error added in v0.0.16

func Error(msg string, err error)

记录详情日志

msg	消息备注
err	错误详情

func ErrorError added in v0.1.1

func ErrorError(msg string, err error) error

记录详情日志

msg	消息备注
err	错误详情

func Ftime added in v0.1.12

func Ftime(t time.Time)

统计函数耗时,用法:defer xlog.Ftime(time.Now())

因内部使用了反射机制,所以无法使用匿名函数进行多层函数名获取 所以此处暂时截至到此处,使用 defer xlog.Ftime(time.Now()) 的固定结构来统计时长 另,因内部使用了 go 队列的形式来进行入库,所以建议此函数使用在正常运行的结构中 可随时退出的命令行记录的话建议使用 defer xlog.RTime(time.Now()) 来记录日志

t	当前时间

func Info added in v0.0.16

func Info(msg string, err error)

记录详情日志

msg	消息备注
err	错误详情

func InfoError added in v0.1.1

func InfoError(msg string, err error) error

记录详情日志

msg	消息备注
err	错误详情

func Notice added in v0.0.16

func Notice(msg string)

记录详情日志

msg	消息备注

func NoticeError added in v0.1.1

func NoticeError(msg string) error

记录详情日志,返回error类型,以便其他方法调用

func Panic added in v0.0.16

func Panic(msg string, err error)

记录详情日志

msg	消息备注
err	错误详情

func PanicError added in v0.1.1

func PanicError(msg string, err error) error

记录详情日志

msg	消息备注
err	错误详情

func Regedit

func Regedit(c *Config)

注入配置项

func Rtime added in v0.1.12

func Rtime(t time.Time)

统计函数耗时,用法:defer xlog.Rtime(time.Now())

因内部使用了反射机制,所以无法使用匿名函数进行多层函数名获取 所以此处暂时截至到此处,使用 defer xlog.Ftime(time.Now()) 的固定结构来统计时长 另,因内部使用了 go 队列的形式来进行入库,所以建议此函数使用在正常运行的结构中 可随时退出的命令行记录的话建议使用 defer xlog.RTime(time.Now()) 来记录日志

t	当前时间

func SaveAny added in v0.0.17

func SaveAny(inf byte, file string, line uint, msg string, err error)

记录日志信息[对外函数,用于记录任意类型/等级的日志信息]

inf		日志等级
file	错误文件
line	错误行号
msg		消息备注
err		错误详情

func SaveAnyError added in v0.1.1

func SaveAnyError(inf byte, file string, line uint, msg string, err error) error

记录日志信息[对外函数,用于记录任意类型/等级的日志信息]

inf		日志等级
file	错误文件
line	错误行号
msg		消息备注
err		错误详情

func User added in v0.0.16

func User(uid uint, typ, info string)

记录用户日志

uid		用户ID
typ		记录类型
info	记录的详细信息

func Warning added in v0.0.16

func Warning(msg string, err error)

记录详情日志

msg	消息备注
err	错误详情

func WarningError added in v0.1.1

func WarningError(msg string, err error) error

记录详情日志

msg	消息备注
err	错误详情

Types

type Config

type Config struct {
	DB          *gorm.DB // 数据库连接
	Console     bool     // 是否输出到控制台中
	TableName   string   // 日志记录的数据表
	RunDir      string   // 程序所在目录
	FuncLogName string   // 函数耗时存储表
}

日志记录模块使用GO携程进行日志记录(此形式可能会存在退出的时候谢程未全部退出的问题,该问题会造成部分日志记录失败的情况) 错误等级:Info -> Notice -> Warning -> Error -> Crit -> Alert -> Panic 错误等级简写:I -> N -> W -> E -> C -> A -> P 备注:此等级中,Crit、Alert、Panic错误为影响到程序正常运行的错误,Error为需要注意,即将影响到正常运行的错误

Panic等级的错误也只是记录到数据库中,而不是直接将程序进行panic退出
记录函数的执行时常
调用方法为:defer xlog.FTime(time.Now())

配置项

type FuncLog added in v0.1.12

type FuncLog struct {
	Id        uint64 `gorm:"column:id;primaryKey;type:BIGINT UNSIGNED;not null;autoIncrement" json:"id" form:"id"` // 条目ID
	Func      string `gorm:"column:func;type:VARCHAR(200);comment:函数名称" json:"func" form:"func"`                   //函数名称
	Line      uint   `gorm:"column:line;type:INT UNSIGNED;comment:调用行数" json:"line" form:"line"`                   //调用行数
	Runtime   uint64 `gorm:"column:runtime;type:BIGINT UNSIGNED;comment:耗时:ns" json:"runtime" form:"runtime"`      // 耗时:ns
	CreatedAt string `gorm:"column:created_at;type:DATETIME;comment:调用时间" json:"created_at" form:"created_at"`     //调用时间
}

函数耗时日志表

func (*FuncLog) TableName added in v0.1.12

func (c *FuncLog) TableName() string

获取表名

type LogStruct added in v0.0.16

type LogStruct struct {
	Id        uint64 `gorm:"column:id;primaryKey;type:BIGINT UNSIGNED;not null;autoIncrement" json:"id" form:"id"` // 条目ID
	Type      string `gorm:"column:type;type:CHAR(1);comment:错误类型;index:error_type" json:"type" form:"type"`       //错误类型,如:I、D等
	File      string `gorm:"column:file;type:VARCHAR(200);comment:错误文件" json:"file" form:"file"`                   //错误文件
	Line      uint   `gorm:"column:line;type:INT UNSIGNED;comment:文件行数" json:"line" form:"line"`                   //错误行数
	Msg       string `gorm:"column:msg;type:VARCHAR(200);comment:消息概述" json:"msg" form:"msg"`                      //错误消息概述
	Content   string `gorm:"column:content;type:TEXT;comment:错误消息内容" json:"content" form:"content"`                //错误信息内容
	CreatedAt string `gorm:"column:created_at;type:DATETIME;comment:创建时间" json:"created_at" form:"created_at"`     //错误发生时间
}

错误信息统计表

func (*LogStruct) TableName added in v0.0.16

func (c *LogStruct) TableName() string

获取表名

Jump to

Keyboard shortcuts

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