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-02-17 21:07:58 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2024-02-17 21:07:58 +0300
commit9f6957ef3f5625db00d5dc22efd99bc8af06cba2 (patch)
tree7d00a17f427b6b2707bdc51c640084896aed15a6
parentd6e05d4a1a9ef206833031a7044c037a1264f7f9 (diff)
[logs] new bug-free log_writer
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
-rw-r--r--web/assets/js/model/xray.js2
-rw-r--r--xray/log_writer.go19
2 files changed, 7 insertions, 14 deletions
diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js
index e9676252..7018fb75 100644
--- a/web/assets/js/model/xray.js
+++ b/web/assets/js/model/xray.js
@@ -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)){
diff --git a/xray/log_writer.go b/xray/log_writer.go
index 53358ca2..2d208326 100644
--- a/xray/log_writer.go
+++ b/xray/log_writer.go
@@ -1,6 +1,7 @@
package xray
import (
+ "regexp"
"strings"
"x-ui/logger"
)
@@ -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 {