Documentation
¶
Overview ¶
日志记录模块
Index ¶
- func Alert(msg string, err error)
- func AlertError(msg string, err error) error
- func Crit(msg string, err error)
- func CritError(msg string, err error) error
- func Debug(msg string, err error)
- func DebugError(msg string, err error) error
- func Error(msg string, err error)
- func ErrorError(msg string, err error) error
- func Ftime(t time.Time)
- func GetLogTypeBigs(typ string, big bool) []string
- func Info(msg string, err error)
- func InfoError(msg string, err error) error
- func Notice(msg string)
- func NoticeError(msg string) error
- func Panic(msg string, err error)
- func PanicError(msg string, err error) error
- func Regedit(c *Config)
- func Rtime(t time.Time)
- func SaveAny(inf byte, file string, line uint, msg string, err error)
- func SaveAnyError(inf byte, file string, line uint, msg string, err error) error
- func User(uid uint, typ, info string)
- func Warning(msg string, err error)
- func WarningError(msg string, err error) error
- type Config
- type FuncLog
- type LogStruct
- type TypeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ftime ¶ added in v0.1.12
统计函数耗时,用法:defer xlog.Ftime(time.Now())
因内部使用了反射机制,所以无法使用匿名函数进行多层函数名获取 所以此处暂时截至到此处,使用 defer xlog.Ftime(time.Now()) 的固定结构来统计时长 另,因内部使用了 go 队列的形式来进行入库,所以建议此函数使用在正常运行的结构中 可随时退出的命令行记录的话建议使用 defer xlog.RTime(time.Now()) 来记录日志
t 当前时间
func Rtime ¶ added in v0.1.12
统计函数耗时,用法:defer xlog.Rtime(time.Now())
因内部使用了反射机制,所以无法使用匿名函数进行多层函数名获取 所以此处暂时截至到此处,使用 defer xlog.Ftime(time.Now()) 的固定结构来统计时长 另,因内部使用了 go 队列的形式来进行入库,所以建议此函数使用在正常运行的结构中 可随时退出的命令行记录的话建议使用 defer xlog.RTime(time.Now()) 来记录日志
t 当前时间
func SaveAny ¶ added in v0.0.17
记录日志信息[对外函数,用于记录任意类型/等级的日志信息]
inf 日志等级 file 错误文件 line 错误行号 msg 消息备注 err 错误详情
func SaveAnyError ¶ added in v0.1.1
记录日志信息[对外函数,用于记录任意类型/等级的日志信息]
inf 日志等级 file 错误文件 line 错误行号 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"` //调用时间 }
函数耗时日志表
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:文件行数;index:error_type" 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"` //错误发生时间 }
错误信息统计表