temp
This commit is contained in:
66
Server/common/log/log.go
Normal file
66
Server/common/log/log.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package log
|
||||
|
||||
import "go.uber.org/zap"
|
||||
|
||||
var globalLogger *zap.SugaredLogger
|
||||
|
||||
// SetLogger 设置日志记录器
|
||||
func SetLogger(logger *zap.SugaredLogger) {
|
||||
if logger == nil {
|
||||
return
|
||||
}
|
||||
globalLogger = logger
|
||||
}
|
||||
|
||||
func GetLogger() *zap.SugaredLogger {
|
||||
return globalLogger
|
||||
}
|
||||
|
||||
// Debugf 打印调试模板日志
|
||||
func Debugf(format string, a ...interface{}) {
|
||||
if globalLogger != nil {
|
||||
globalLogger.Debugf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// Infof 打印信息模板日志
|
||||
func Infof(format string, a ...interface{}) {
|
||||
if globalLogger != nil {
|
||||
globalLogger.Infof(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// Warnf 打印警告模板日志
|
||||
func Warnf(format string, a ...interface{}) {
|
||||
if globalLogger != nil {
|
||||
globalLogger.Warnf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// Errorf 打印错误模板日志
|
||||
func Errorf(format string, a ...interface{}) {
|
||||
if globalLogger != nil {
|
||||
globalLogger.Errorf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// Panicf 打印Panic模板日志
|
||||
func Panicf(format string, a ...interface{}) {
|
||||
if globalLogger != nil {
|
||||
globalLogger.Panicf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// Fatalf 打印致命错误模板日志
|
||||
func Fatalf(format string, a ...interface{}) {
|
||||
if globalLogger != nil {
|
||||
globalLogger.Fatalf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// Close 关闭日志
|
||||
func Close() {
|
||||
if globalLogger != nil {
|
||||
_ = globalLogger.Sync()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user