Browse Source

fix log writer crash

Co-Authored-By: Alireza Ahmadi <[email protected]>
MHSanaei 1 year ago
parent
commit
1f9b3730d4
1 changed files with 6 additions and 1 deletions
  1. 6 1
      xray/log_writer.go

+ 6 - 1
xray/log_writer.go

@@ -20,8 +20,13 @@ func (lw *LogWriter) Write(m []byte) (n int, err error) {
 	lw.lastLine = messages[len(messages)-1]
 
 	for _, msg := range messages {
+		messageBody := msg
+
 		// Remove timestamp
-		messageBody := strings.TrimSpace(strings.SplitN(msg, " ", 3)[2])
+		splittedMsg := strings.SplitN(msg, " ", 3)
+		if len(splittedMsg) > 2 {
+			messageBody = strings.TrimSpace(strings.SplitN(msg, " ", 3)[2])
+		}
 
 		// Find level in []
 		startIndex := strings.Index(messageBody, "[")