Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormhsanaei <ho3ein.sanaei@gmail.com>2024-12-04 01:07:24 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2024-12-04 01:07:24 +0300
commit4c4cc362b37f6c23ab3a79651d0c0e67cc70974d (patch)
tree121d699b0877a011c28bfa2ed98c037f669cbe39
parent4e0aca16c22be4d6feb842bca8dc94141c2db775 (diff)
fix crash report
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
-rw-r--r--xray/log_writer.go20
-rw-r--r--xray/process.go5
2 files changed, 19 insertions, 6 deletions
diff --git a/xray/log_writer.go b/xray/log_writer.go
index c8d966b5..cc00d541 100644
--- a/xray/log_writer.go
+++ b/xray/log_writer.go
@@ -16,11 +16,24 @@ 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}) \[([^\]]+)\] (.+)$`)
+ crashRegex := regexp.MustCompile(`(?i)(panic|exception|stack trace|fatal error)`)
+
// Convert the data to a string
message := strings.TrimSpace(string(m))
+
+ // Check if the message contains a crash
+ if crashRegex.MatchString(message) {
+ logger.Debug("Core crash detected:\n", message)
+ lw.lastLine = message
+ err1 := writeCrachReport(m)
+ if err1 != nil {
+ logger.Error("Unable to write crash report:", err1)
+ }
+ return len(m), nil
+ }
+
+ regex := regexp.MustCompile(`^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[([^\]]+)\] (.+)$`)
messages := strings.Split(message, "\n")
- lw.lastLine = messages[len(messages)-1]
for _, msg := range messages {
matches := regex.FindStringSubmatch(msg)
@@ -42,9 +55,10 @@ func (lw *LogWriter) Write(m []byte) (n int, err error) {
default:
logger.Debug("XRAY: " + msg)
}
+ lw.lastLine = ""
} else if msg != "" {
logger.Debug("XRAY: " + msg)
- return len(m), nil
+ lw.lastLine = msg
}
}
diff --git a/xray/process.go b/xray/process.go
index 58d14a1f..b4947864 100644
--- a/xray/process.go
+++ b/xray/process.go
@@ -226,7 +226,6 @@ func (p *process) Start() (err error) {
if err != nil {
logger.Error("Failure in running xray-core:", err)
p.exitErr = err
- p.witeCrachReport(err)
}
}()
@@ -243,7 +242,7 @@ func (p *process) Stop() error {
return p.cmd.Process.Signal(syscall.SIGTERM)
}
-func (p *process) witeCrachReport(err error) error {
+func writeCrachReport(m []byte) error {
crashReportPath := config.GetBinFolderPath() + "/core_crash_" + time.Now().Format("20060102_150405") + ".log"
- return os.WriteFile(crashReportPath, []byte(err.Error()), os.ModePerm)
+ return os.WriteFile(crashReportPath, m, os.ModePerm)
}