Skip to content

Commit 217acad

Browse files
Add files via upload
1 parent 468fce1 commit 217acad

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

core_engine/main.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"os"
1212
"os/exec"
13+
"strings"
1314
"sync"
1415
"time"
1516

@@ -57,7 +58,7 @@ func main() {
5758

5859
fullConfig := map[string]interface{}{
5960
"log": map[string]string{
60-
"loglevel": "debug", // ! Enable debug logging
61+
"loglevel": "debug", // Enable debug logging for detailed output
6162
},
6263
"inbounds": []map[string]interface{}{
6364
{"protocol": "socks", "port": c.TestPort, "listen": "127.0.0.1", "settings": map[string]interface{}{"auth": "noauth", "udp": true}},
@@ -74,7 +75,7 @@ func main() {
7475

7576
cmd := exec.CommandContext(ctx, c.XrayPath, "-c", tmpFile.Name())
7677

77-
// ! Capture Xray's output
78+
// Capture Xray's stdout and stderr
7879
var xrayOutput bytes.Buffer
7980
cmd.Stdout = &xrayOutput
8081
cmd.Stderr = &xrayOutput
@@ -84,17 +85,20 @@ func main() {
8485
return
8586
}
8687

87-
time.Sleep(800 * time.Millisecond) // Increased sleep time slightly for debug logs
88+
time.Sleep(800 * time.Millisecond)
8889

8990
ping, status := testProxy(c.TestPort)
9091

91-
// ! If test fails, append Xray's log to the status
92+
// If the test fails, append Xray's log to the status for debugging
9293
if status != "success" {
93-
// Sanitize and shorten the log for cleaner output
9494
logStr := string(xrayOutput.Bytes())
95-
logStr = re.SubexpNames(logStr, -1)
96-
if len(logStr) > 200 {
97-
logStr = logStr[:200]
95+
96+
// ! FIX: Use 'strings.ReplaceAll' to make the log a single line. No more 're'.
97+
logStr = strings.ReplaceAll(logStr, "\n", " ")
98+
logStr = strings.ReplaceAll(logStr, "\r", "")
99+
100+
if len(logStr) > 250 {
101+
logStr = logStr[:250] // Shorten the log for cleaner output
98102
}
99103
status = fmt.Sprintf("%s | xray_log: %s", status, logStr)
100104
}
@@ -124,7 +128,7 @@ func testProxy(port int) (int64, string) {
124128

125129
dialer, err := proxy.SOCKS5("tcp", fmt.Sprintf("127.0.0.1:%d", port), nil, proxy.Direct)
126130
if err != nil {
127-
return -1, "failed_dialer"
131+
return -1, fmt.Sprintf("failed_dialer: %v", err)
128132
}
129133

130134
httpTransport := &http.Transport{}

0 commit comments

Comments
 (0)