Skip to content

Commit

Permalink
日志优化
Browse files Browse the repository at this point in the history
  • Loading branch information
rushuinet committed Dec 23, 2020
1 parent 3db6d78 commit 8f93276
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package xxl
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -113,7 +112,7 @@ func (e *executor) runTask(writer http.ResponseWriter, request *http.Request) {
e.log.Error("参数解析错误:" + string(req))
return
}
fmt.Printf("任务参数:%v", param)
e.log.Info("任务参数:%v", param)
if !e.regList.Exists(param.ExecutorHandler) {
_, _ = writer.Write(returnCall(param, 500, "Task not registered"))
e.log.Error("任务[" + Int64ToStr(param.JobID) + "]没有注册:" + param.ExecutorHandler)
Expand All @@ -129,6 +128,7 @@ func (e *executor) runTask(writer http.ResponseWriter, request *http.Request) {
task.Id = param.JobID
task.Name = param.ExecutorHandler
task.Param = param
task.log = e.log

//阻塞策略处理
if e.runList.Exists(Int64ToStr(task.Id)) {
Expand Down
5 changes: 3 additions & 2 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package xxl
import (
"context"
"fmt"
"log"
"runtime/debug"
)

Expand All @@ -20,13 +19,15 @@ type Task struct {
Cancel context.CancelFunc
StartTime int64
EndTime int64
//日志
log Logger
}

//运行任务
func (t *Task) Run(callback func(code int64, msg string)) {
defer func(cancel func()) {
if err := recover(); err != nil {
log.Println(t.Info()+" panic: ", err)
t.log.Info(t.Info()+" panic: %v", err)
debug.PrintStack() //堆栈跟踪
callback(500, "task panic:"+fmt.Sprintf("%v", err))
cancel()
Expand Down

0 comments on commit 8f93276

Please sign in to comment.