|
|
@@ -148,8 +148,7 @@ var logFiles = map[string]string{
|
|
|
func serviceLogHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
unit := r.URL.Query().Get("unit")
|
|
|
if unit == "" {
|
|
|
- http.Error(w, "missing unit",
|
|
|
- http.StatusBadRequest)
|
|
|
+ http.Error(w, "missing unit", http.StatusBadRequest)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -160,8 +159,7 @@ func serviceLogHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
flusher, ok := w.(http.Flusher)
|
|
|
if !ok {
|
|
|
- http.Error(w, "not supported",
|
|
|
- http.StatusInternalServerError)
|
|
|
+ http.Error(w, "not supported", http.StatusInternalServerError)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -202,8 +200,9 @@ func serviceLogHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ id := time.Now().UnixNano()
|
|
|
if true {
|
|
|
- baseapp.Logger.Debugf("[服务日志流启动] unit=%s", unit)
|
|
|
+ baseapp.Logger.Debugf("[服务日志流启动] id=%d unit=%s", id, unit)
|
|
|
}
|
|
|
|
|
|
defer func() {
|
|
|
@@ -212,23 +211,33 @@ func serviceLogHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
cmd.Wait()
|
|
|
|
|
|
- baseapp.Logger.Debugf("[服务日志流关闭] unit=%s", unit)
|
|
|
+ baseapp.Logger.Debugf("[服务日志流关闭] id=%d unit=%s", id, unit)
|
|
|
}()
|
|
|
|
|
|
- scanner := bufio.NewScanner(stdout)
|
|
|
+ lines := make(chan string, 100)
|
|
|
|
|
|
- for scanner.Scan() {
|
|
|
- select {
|
|
|
- case <-r.Context().Done():
|
|
|
- return
|
|
|
- default:
|
|
|
+ go func() {
|
|
|
+ scanner := bufio.NewScanner(stdout)
|
|
|
+ scanner.Buffer(make([]byte, 1024), 1024*1024)
|
|
|
+ for scanner.Scan() {
|
|
|
+ lines <- scanner.Text()
|
|
|
}
|
|
|
+ close(lines)
|
|
|
+ }()
|
|
|
|
|
|
- if _, err := fmt.Fprintf(w, "data: %s\n\n", scanner.Text()); err != nil {
|
|
|
+ for {
|
|
|
+ select {
|
|
|
+ case <-r.Context().Done():
|
|
|
return
|
|
|
+ case line, ok := <-lines:
|
|
|
+ if !ok {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if _, err := fmt.Fprintf(w, "data: %s\n\n", line); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ flusher.Flush()
|
|
|
}
|
|
|
-
|
|
|
- flusher.Flush()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -267,7 +276,6 @@ func callRPCResult(ctx context.Context, port int, method string, params any, res
|
|
|
|
|
|
client, err := jsonrpc2.NewRPCClient(url)
|
|
|
if err != nil {
|
|
|
- baseapp.Logger.Errorf("[执行RPC错误] %s err=%v\n", method, err)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
@@ -276,7 +284,7 @@ func callRPCResult(ctx context.Context, port int, method string, params any, res
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- baseapp.Logger.Debugf("[发送RPC应答] %s result=%s\n", method, string(resp.Result))
|
|
|
+ baseapp.Logger.Debugf("[发送RPC应答] %s result=%s err=%v\n", method, string(resp.Result), resp.Error)
|
|
|
|
|
|
return json.Unmarshal(resp.Result, result)
|
|
|
}
|
|
|
@@ -295,12 +303,11 @@ func callRPCResponse(w http.ResponseWriter, r *http.Request, port int, method st
|
|
|
|
|
|
resp, err := client.Call(r.Context(), method, params)
|
|
|
if err != nil {
|
|
|
- baseapp.Logger.Errorf("[执行RPC错误] %s err=%v\n", method, err)
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- baseapp.Logger.Debugf("[发送RPC应答] %s result=%s\n", method, string(resp.Result))
|
|
|
+ baseapp.Logger.Debugf("[发送RPC应答] %s result=%s err=%v\n", method, string(resp.Result), resp.Error)
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
json.NewEncoder(w).Encode(resp.Result)
|