Xray log: show failed on error log level

This commit is contained in:
mhsanaei 2025-03-10 14:12:30 +01:00
parent f7f95ffbae
commit 422c391f96
No known key found for this signature in database
GPG key ID: D875CD086CF668A0

View file

@ -33,16 +33,18 @@ 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}\.\d{6}) \[([^\]]+)\] (.+)$`) regex := regexp.MustCompile(`^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}\.\d{6}) \[([^\]]+)\] (.+)$`)
messages := strings.Split(message, "\n") messages := strings.SplitSeq(message, "\n")
for _, msg := range messages { for msg := range messages {
matches := regex.FindStringSubmatch(msg) matches := regex.FindStringSubmatch(msg)
if len(matches) > 3 { if len(matches) > 3 {
level := matches[2] level := matches[2]
msgBody := matches[3] msgBody := matches[3]
// Map the level to the appropriate logger function if strings.Contains(strings.ToLower(msgBody), "failed") {
logger.Error("XRAY: " + msgBody)
} else {
switch level { switch level {
case "Debug": case "Debug":
logger.Debug("XRAY: " + msgBody) logger.Debug("XRAY: " + msgBody)
@ -55,9 +57,14 @@ func (lw *LogWriter) Write(m []byte) (n int, err error) {
default: default:
logger.Debug("XRAY: " + msg) logger.Debug("XRAY: " + msg)
} }
}
lw.lastLine = "" lw.lastLine = ""
} else if msg != "" { } else if msg != "" {
if strings.Contains(strings.ToLower(msg), "failed") {
logger.Error("XRAY: " + msg)
} else {
logger.Debug("XRAY: " + msg) logger.Debug("XRAY: " + msg)
}
lw.lastLine = msg lw.lastLine = msg
} }
} }