Skip to content

Commit

Permalink
规范日志输出
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 9, 2022
1 parent 34f4382 commit 497ebca
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 148 deletions.
77 changes: 0 additions & 77 deletions cmd/import.go

This file was deleted.

12 changes: 6 additions & 6 deletions importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/yaoapp/gou"
"github.com/yaoapp/kun/any"
"github.com/yaoapp/kun/exception"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/importer/from"
"github.com/yaoapp/yao/importer/xlsx"
"github.com/yaoapp/yao/share"
"github.com/yaoapp/yao/xfs"
"github.com/yaoapp/yao/xlog"
)

// Importers 导入器
Expand Down Expand Up @@ -163,12 +163,12 @@ func (imp *Importer) DataClean(data [][]interface{}, bindings []*Binding) ([]str
func DataValidate(row []interface{}, value interface{}, rule string) ([]interface{}, bool) {
process, err := gou.ProcessOf(rule, value, row)
if err != nil {
xlog.Printf("DataValidate: %s %s", rule, err.Error())
log.With(log.F{"rule": rule, "row": row}).Error("DataValidate: %s", err.Error())
return row, true
}
res, err := process.Exec()
if err != nil {
xlog.Printf("DataValidate: %s %s", rule, err.Error())
log.With(log.F{"rule": rule, "row": row}).Error("DataValidate: %s", err.Error())
return row, true
}

Expand Down Expand Up @@ -397,14 +397,14 @@ func (imp *Importer) Run(src from.Source, mapping *Mapping) map[string]int {
process, err := gou.ProcessOf(imp.Process, columns, data)
if err != nil {
failed = failed + length
xlog.Printf("导入失败 %d %s ", line, err.Error())
log.With(log.F{"line": line}).Error("导入失败: %s", err.Error())
return
}

response, err := process.Exec()
if err != nil {
failed = failed + length
xlog.Printf("导入失败 %d %s ", line, err.Error())
log.With(log.F{"line": line}).Error("导入失败: %s", err.Error())
return
}

Expand All @@ -422,7 +422,7 @@ func (imp *Importer) Run(src from.Source, mapping *Mapping) map[string]int {
return
}

xlog.Printf("导入处理器未返回失败结果 %#v %d %d", response, line, length)
log.With(log.F{"line": line, "response": response, "length": length}).Error("导入处理器未返回失败结果")
})
return map[string]int{
"total": total,
Expand Down
8 changes: 4 additions & 4 deletions importer/xlsx/xlsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/xuri/excelize/v2"
"github.com/yaoapp/kun/exception"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/yao/importer/from"
"github.com/yaoapp/yao/xlog"
)

// Xlsx xlsx file
Expand Down Expand Up @@ -54,7 +54,7 @@ func Open(filename string) *Xlsx {
// Close 关闭文件句柄
func (xlsx *Xlsx) Close() error {
if err := xlsx.File.Close(); err != nil {
xlog.Println(err.Error())
log.Error("Close file error: %s", err.Error())
return err
}
return nil
Expand Down Expand Up @@ -122,7 +122,7 @@ func (xlsx *Xlsx) readLine(line int, axises []string) ([]interface{}, bool) {
axis := positionToAxis(line, c)
value, err = xlsx.File.GetCellValue(xlsx.SheetName, axis)
if err != nil {
xlog.Printf("读取数据出错 %s %s %s", xlsx.SheetName, axis, err.Error())
log.With(log.F{"SheetName": xlsx.SheetName, "axis": axis}).Error("读取数据出错 %s", err.Error())
value = ""
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (xlsx *Xlsx) Columns() []from.Column {
}
cellType, err := xlsx.File.GetCellType(xlsx.SheetName, axis)
if err != nil {
xlog.Printf("读取数据类型失败 %s", err.Error())
log.With(log.F{"SheetName": xlsx.SheetName, "axis": axis}).Error("读取数据类型失败 %s", err.Error())
}
columns = append(columns, from.Column{
Name: cell,
Expand Down
8 changes: 3 additions & 5 deletions service/guard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/helper"
"github.com/yaoapp/yao/xlog"
)

// Guards 服务中间件
Expand All @@ -27,15 +27,13 @@ func bearerJWT(c *gin.Context) {
}

tokenString = strings.TrimSpace(strings.TrimPrefix(tokenString, "Bearer "))
if config.Conf.Mode == "debug" {
xlog.Printf("JWT: %s Secret: %s", tokenString, config.Conf.JWTSecret)
}
log.Debug("JWT: %s Secret: %s", tokenString, config.Conf.JWTSecret)
token, err := jwt.ParseWithClaims(tokenString, &helper.JwtClaims{}, func(token *jwt.Token) (interface{}, error) {
return []byte(config.Conf.JWTSecret), nil
})

if err != nil {
xlog.Printf("JWT ParseWithClaims Error: %s", err)
log.Error("JWT ParseWithClaims Error: %s", err)
c.JSON(403, gin.H{"code": 403, "message": fmt.Sprintf("登录已过期或令牌失效(%s)", err)})
c.Abort()
return
Expand Down
11 changes: 4 additions & 7 deletions share/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/yaoapp/gou/session"
"github.com/yaoapp/kun/any"
"github.com/yaoapp/kun/exception"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/kun/maps"
"github.com/yaoapp/kun/utils"
"github.com/yaoapp/yao/xlog"
)

// IsAllow 鉴权处理程序
Expand Down Expand Up @@ -118,20 +118,17 @@ func (api API) MergeDefaultQueryParam(param gou.QueryParam, i int, sid string) g

// GetQueryParam 解析参数
func GetQueryParam(v interface{}, sid string) gou.QueryParam {
fmt.Println("\n==== GetQueryParam ===== SID:", sid)
log.With(log.F{"sid": sid}).Trace("GetQueryParam Entry")
data := map[string]interface{}{}
if sid != "" {
var err error
ss := session.Global().ID(sid)
data, err = ss.Dump()
utils.Dump(data)
log.With(log.F{"data": data}).Trace("GetQueryParam Session Data")
if err != nil {
xlog.Printf("读取会话信息出错 %s", err.Error())
log.Error("读取会话信息出错 %s", err.Error())
}
}
fmt.Println("==== GetQueryParam========================")
fmt.Println("")

v = share.Bind(v, maps.Of(data).Dot())
param, ok := gou.AnyToQueryParam(v)
if !ok {
Expand Down
8 changes: 3 additions & 5 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import (
"github.com/yaoapp/gou/helper"
"github.com/yaoapp/kun/exception"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/kun/maps"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/share"
"github.com/yaoapp/yao/xlog"
)

// Tables 已载入模型
Expand Down Expand Up @@ -182,7 +180,7 @@ func (table *Table) Before(process string, processArgs []interface{}, sid string

response, err := gou.NewProcess(process, args...).WithSID(sid).Exec()
if err != nil {
xlog.Println("Hook执行失败: ", err.Error(), maps.StrAny{"process": process, "args": args})
log.With(log.F{"process": process, "args": args}).Warn("Hook执行失败: ", err.Error())
return processArgs
}

Expand All @@ -191,7 +189,7 @@ func (table *Table) Before(process string, processArgs []interface{}, sid string
return res
}

xlog.Println("Hook执行失败: 无效的处理器", maps.StrAny{"process": process, "response": response})
log.With(log.F{"process": process, "args": args}).Warn("Hook执行失败: 无效的处理器")
return processArgs
}

Expand All @@ -203,7 +201,7 @@ func (table *Table) After(process string, data interface{}, args []interface{},
args = append([]interface{}{data}, args...)
response, err := gou.NewProcess(process, args...).WithSID(sid).Exec()
if err != nil {
xlog.Println("Hook执行失败: ", err.Error(), maps.StrAny{"process": process, "args": args})
log.With(log.F{"process": process, "args": args}).Warn("Hook执行失败: ", err.Error())
return data
}
return response
Expand Down
5 changes: 1 addition & 4 deletions workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/helper"
"github.com/yaoapp/yao/share"
"github.com/yaoapp/yao/xlog"
)

// Process
Expand Down Expand Up @@ -64,9 +63,7 @@ func LoadWorkFlow(source []byte, name string) (*WorkFlow, error) {
workflow := WorkFlow{Name: name, Source: source}
err := jsoniter.Unmarshal(source, &workflow)
if err != nil {
xlog.Println(name)
xlog.Println(err.Error())
xlog.Println(string(source))
log.With(log.F{"name": name, "source": source}).Error("LoadWorkFlow: %s", err.Error())
return nil, err
}

Expand Down
40 changes: 0 additions & 40 deletions xlog/xlog.go

This file was deleted.

0 comments on commit 497ebca

Please sign in to comment.