Skip to content

Commit

Permalink
[logs] new bug-free log_writer
Browse files Browse the repository at this point in the history
Co-Authored-By: Alireza Ahmadi <[email protected]>
  • Loading branch information
MHSanaei and alireza0 committed Feb 17, 2024
1 parent d6e05d4 commit 9f6957e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion web/assets/js/model/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ class Inbound extends XrayCommonClass {
const orderChars = remarkModel.slice(1);
let orders = {
'i': remark,
'e': client ? client.email : '',
'e': email,
'o': '',
};
if(ObjectUtil.isArrEmpty(this.stream.externalProxy)){
Expand Down
19 changes: 6 additions & 13 deletions xray/log_writer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xray

import (
"regexp"
"strings"
"x-ui/logger"
)
Expand All @@ -14,26 +15,18 @@ type LogWriter struct {
}

func (lw *LogWriter) Write(m []byte) (n int, err error) {
regex := regexp.MustCompile(`^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[([^\]]+)\] (.+)$`)
// Convert the data to a string
message := strings.TrimSpace(string(m))
messages := strings.Split(message, "\n")
lw.lastLine = messages[len(messages)-1]

for _, msg := range messages {
messageBody := msg
matches := regex.FindStringSubmatch(msg)

// Remove timestamp
splittedMsg := strings.SplitN(msg, " ", 3)
if len(splittedMsg) > 2 {
messageBody = strings.TrimSpace(strings.SplitN(msg, " ", 3)[2])
}

// Find level in []
startIndex := strings.Index(messageBody, "[")
endIndex := strings.Index(messageBody, "]")
if startIndex != -1 && endIndex != -1 && startIndex < endIndex {
level := strings.TrimSpace(messageBody[startIndex+1 : endIndex])
msgBody := "XRAY: " + strings.TrimSpace(messageBody[endIndex+1:])
if len(matches) > 3 {
level := matches[2]
msgBody := matches[3]

// Map the level to the appropriate logger function
switch level {
Expand Down

0 comments on commit 9f6957e

Please sign in to comment.