|
@@ -8,6 +8,13 @@ import (
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+// Compiled once at package load: Write runs on every line Xray emits, so
|
|
|
|
|
+// recompiling these per write is wasted work.
|
|
|
|
|
+var (
|
|
|
|
|
+ crashRegex = regexp.MustCompile(`(?i)(panic|exception|stack trace|fatal error)`)
|
|
|
|
|
+ logLineRegex = regexp.MustCompile(`^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}\.\d{6}) \[([^\]]+)\] (.+)$`)
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
// NewLogWriter returns a new LogWriter for processing Xray log output.
|
|
// NewLogWriter returns a new LogWriter for processing Xray log output.
|
|
|
func NewLogWriter() *LogWriter {
|
|
func NewLogWriter() *LogWriter {
|
|
|
return &LogWriter{}
|
|
return &LogWriter{}
|
|
@@ -20,8 +27,6 @@ type LogWriter struct {
|
|
|
|
|
|
|
|
// Write processes and filters log output from the Xray process, handling crash detection and message filtering.
|
|
// Write processes and filters log output from the Xray process, handling crash detection and message filtering.
|
|
|
func (lw *LogWriter) Write(m []byte) (n int, err error) {
|
|
func (lw *LogWriter) Write(m []byte) (n int, err error) {
|
|
|
- crashRegex := regexp.MustCompile(`(?i)(panic|exception|stack trace|fatal error)`)
|
|
|
|
|
-
|
|
|
|
|
// Convert the data to a string
|
|
// Convert the data to a string
|
|
|
message := strings.TrimSpace(string(m))
|
|
message := strings.TrimSpace(string(m))
|
|
|
msgLowerAll := strings.ToLower(message)
|
|
msgLowerAll := strings.ToLower(message)
|
|
@@ -42,11 +47,10 @@ func (lw *LogWriter) Write(m []byte) (n int, err error) {
|
|
|
return len(m), nil
|
|
return len(m), nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- regex := regexp.MustCompile(`^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}\.\d{6}) \[([^\]]+)\] (.+)$`)
|
|
|
|
|
messages := strings.SplitSeq(message, "\n")
|
|
messages := strings.SplitSeq(message, "\n")
|
|
|
|
|
|
|
|
for msg := range messages {
|
|
for msg := range messages {
|
|
|
- matches := regex.FindStringSubmatch(msg)
|
|
|
|
|
|
|
+ matches := logLineRegex.FindStringSubmatch(msg)
|
|
|
|
|
|
|
|
if len(matches) > 3 {
|
|
if len(matches) > 3 {
|
|
|
level := matches[2]
|
|
level := matches[2]
|