Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
91f65064ff | ||
![]() |
06d888e8de | ||
![]() |
f6c7d66376 |
50
log/log.go
50
log/log.go
@@ -3,7 +3,7 @@ package log
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ const (
|
||||
)
|
||||
|
||||
type Operator struct {
|
||||
ID int // 系统ID设置0
|
||||
ID int `json:"id"` // 系统ID设置0
|
||||
OperatorType OperatorType `json:"operator_type"`
|
||||
}
|
||||
|
||||
@@ -49,14 +49,18 @@ type LogInfo struct {
|
||||
Result interface{} `json:"result,omitempty"` // 结果,返回值,传指针,如果是报错,传err
|
||||
}
|
||||
|
||||
type param struct {
|
||||
Type string `json:"type"`
|
||||
Value interface{} `json:"value"`
|
||||
type TempGLog struct {
|
||||
Time string `json:"Time"`
|
||||
TraceId string `json:"TraceId"`
|
||||
Level string `json:"Level"`
|
||||
Content string `json:"Content"`
|
||||
}
|
||||
|
||||
type result struct {
|
||||
Type string `json:"type"`
|
||||
Value interface{} `json:"value"`
|
||||
type GLog struct {
|
||||
Time string `json:"Time"`
|
||||
TraceId string `json:"TraceId"`
|
||||
Level string `json:"Level"`
|
||||
Content *LogInfo `json:"Content"`
|
||||
}
|
||||
|
||||
func ZapDebug(logger *zap.Logger, log *LogInfo) {
|
||||
@@ -96,43 +100,43 @@ func HandleLog(log *LogInfo) {
|
||||
log.Result = processValue(log.Result)
|
||||
}
|
||||
|
||||
func GFInfo(ctx context.Context, log *LogInfo) {
|
||||
func GFInfo(ctx context.Context, g *glog.Logger, log *LogInfo) {
|
||||
HandleLog(log)
|
||||
g.Log().Info(ctx, log)
|
||||
g.Info(ctx, log)
|
||||
}
|
||||
|
||||
func GFWarning(ctx context.Context, log *LogInfo) {
|
||||
func GFWarning(ctx context.Context, g *glog.Logger, log *LogInfo) {
|
||||
HandleLog(log)
|
||||
g.Log().Warning(ctx, log)
|
||||
g.Warning(ctx, log)
|
||||
}
|
||||
|
||||
func GFError(ctx context.Context, log *LogInfo) {
|
||||
func GFError(ctx context.Context, g *glog.Logger, log *LogInfo) {
|
||||
HandleLog(log)
|
||||
g.Log().Error(ctx, log)
|
||||
g.Error(ctx, log)
|
||||
}
|
||||
|
||||
func GFDebug(ctx context.Context, log *LogInfo) {
|
||||
func GFDebug(ctx context.Context, g *glog.Logger, log *LogInfo) {
|
||||
HandleLog(log)
|
||||
g.Log().Debug(ctx, log)
|
||||
g.Debug(ctx, log)
|
||||
}
|
||||
|
||||
func GFPanic(ctx context.Context, log *LogInfo) {
|
||||
func GFPanic(ctx context.Context, g *glog.Logger, log *LogInfo) {
|
||||
HandleLog(log)
|
||||
g.Log().Panic(ctx, log)
|
||||
g.Panic(ctx, log)
|
||||
}
|
||||
|
||||
func GFFatal(ctx context.Context, log *LogInfo) {
|
||||
func GFFatal(ctx context.Context, g *glog.Logger, log *LogInfo) {
|
||||
HandleLog(log)
|
||||
g.Log().Fatal(ctx, log)
|
||||
g.Fatal(ctx, log)
|
||||
}
|
||||
|
||||
func (l *LogInfo) GFCommonHandelResult(ctx context.Context, result interface{}, err error) {
|
||||
func (l *LogInfo) GFCommonHandelResult(ctx context.Context, g *glog.Logger, result interface{}, err error) {
|
||||
if err != nil {
|
||||
l.Result = err
|
||||
GFError(ctx, l)
|
||||
GFError(ctx, g, l)
|
||||
} else {
|
||||
l.Result = result
|
||||
GFInfo(ctx, l)
|
||||
GFInfo(ctx, g, l)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user