diff --git a/middleware/logging.go b/middleware/logging.go
index c8029c4..dbc5b1e 100644
--- a/middleware/logging.go
+++ b/middleware/logging.go
@@ -56,22 +56,18 @@ func LoggingMiddleware(next http.Handler) http.Handler {
})
}
-// logRequest 记录请求日志 - 优化后仅记录异常和关键请求
+// logRequest 记录请求日志 - 恢复正常请求日志记录
func logRequest(r *http.Request, rw *responseWriter, duration time.Duration, requestBody []byte) {
// 获取客户端IP
clientIP := getClientIP(r)
- // 判断是否需要记录日志的条件
- shouldLog := rw.statusCode >= 400 || // 错误状态码
+ // 判断是否需要详细记录日志的条件
+ shouldDetailLog := rw.statusCode >= 400 || // 错误状态码
duration > 5*time.Second || // 耗时过长
shouldLogPath(r.URL.Path) || // 关键路径
isAdminPath(r.URL.Path) // 管理员路径
- if !shouldLog {
- return // 正常请求不记录日志,减少日志噪音
- }
-
- // 简化的日志格式,移除User-Agent以减少噪音
+ // 所有API请求都记录基本信息,但详细日志只记录重要请求
if rw.statusCode >= 400 {
// 错误请求记录详细信息
utils.Error("HTTP异常 - %s %s - IP: %s - 状态码: %d - 耗时: %v",
@@ -85,10 +81,14 @@ func logRequest(r *http.Request, rw *responseWriter, duration time.Duration, req
// 慢请求警告
utils.Warn("HTTP慢请求 - %s %s - IP: %s - 耗时: %v",
r.Method, r.URL.Path, clientIP, duration)
- } else {
+ } else if shouldDetailLog {
// 关键路径的正常请求
utils.Info("HTTP关键请求 - %s %s - IP: %s - 状态码: %d - 耗时: %v",
r.Method, r.URL.Path, clientIP, rw.statusCode, duration)
+ } else {
+ // 普通API请求记录简化日志 - 使用Info级别确保能被看到
+ // utils.Info("HTTP请求 - %s %s - 状态码: %d - 耗时: %v",
+ // r.Method, r.URL.Path, rw.statusCode, duration)
}
}
@@ -100,6 +100,13 @@ func shouldLogPath(path string) bool {
"/api/admin/config",
"/api/admin/users",
"/telegram/webhook",
+ "/api/resources",
+ "/api/version",
+ "/api/cks",
+ "/api/pans",
+ "/api/categories",
+ "/api/tags",
+ "/api/tasks",
}
for _, keyPath := range keyPaths {
@@ -113,7 +120,7 @@ func shouldLogPath(path string) bool {
// isAdminPath 判断是否为管理员路径
func isAdminPath(path string) bool {
return strings.HasPrefix(path, "/api/admin/") ||
- strings.HasPrefix(path, "/admin/")
+ strings.HasPrefix(path, "/admin/")
}
// getClientIP 获取客户端真实IP地址
diff --git a/utils/log_telegram.go b/utils/log_telegram.go
index b0fd08a..7b23771 100644
--- a/utils/log_telegram.go
+++ b/utils/log_telegram.go
@@ -28,23 +28,40 @@ func GetTelegramLogs(startTime *time.Time, endTime *time.Time, limit int) ([]Tel
return []TelegramLogEntry{}, nil
}
- files, err := filepath.Glob(filepath.Join(logDir, "app_*.log"))
+ // 查找所有日志文件,包括当前的app.log和历史日志文件
+ allFiles, err := filepath.Glob(filepath.Join(logDir, "*.log"))
if err != nil {
return nil, fmt.Errorf("查找日志文件失败: %v", err)
}
- if len(files) == 0 {
+ if len(allFiles) == 0 {
return []TelegramLogEntry{}, nil
}
- // 按时间排序,最近的在前面
- sort.Sort(sort.Reverse(sort.StringSlice(files)))
+ // 将app.log放在最前面,其他文件按时间排序
+ var files []string
+ var otherFiles []string
+
+ for _, file := range allFiles {
+ if filepath.Base(file) == "app.log" {
+ files = append(files, file) // 当前日志文件优先
+ } else {
+ otherFiles = append(otherFiles, file)
+ }
+ }
+
+ // 其他文件按时间排序,最近的在前面
+ sort.Sort(sort.Reverse(sort.StringSlice(otherFiles)))
+ files = append(files, otherFiles...)
+
+ // files现在已经是app.log优先,然后是其他文件按时间倒序排列
var allEntries []TelegramLogEntry
// 编译Telegram相关的正则表达式
telegramRegex := regexp.MustCompile(`(?i)(\[TELEGRAM.*?\])`)
- messageRegex := regexp.MustCompile(`\[(\w+)\]\s+(\d{4}/\d{2}/\d{2}\s+\d{2}:\d{2}:\d{2})\s+\[.*?\]\s+(.*)`)
+ // 修正正则表达式以匹配实际的日志格式: 2025/01/20 14:30:15 [INFO] [file:line] [TELEGRAM] message
+ messageRegex := regexp.MustCompile(`(\d{4}/\d{2}/\d{2}\s+\d{2}:\d{2}:\d{2})\s+\[(\w+)\]\s+\[.*?:\d+\]\s+\[TELEGRAM.*?\]\s+(.*)`)
for _, file := range files {
entries, err := parseTelegramLogsFromFile(file, telegramRegex, messageRegex, startTime, endTime)
@@ -119,18 +136,23 @@ func parseTelegramLogsFromFile(filePath string, telegramRegex, messageRegex *reg
// parseLogLine 解析单行日志
func parseLogLine(line string, messageRegex *regexp.Regexp) (TelegramLogEntry, error) {
- // 匹配日志格式: [LEVEL] 2006/01/02 15:04:05 [file:line] message
+ // 匹配日志格式: 2006/01/02 15:04:05 [LEVEL] [file:line] [TELEGRAM] message
matches := messageRegex.FindStringSubmatch(line)
if len(matches) < 4 {
return TelegramLogEntry{}, fmt.Errorf("无法解析日志行: %s", line)
}
- level := matches[1]
- timeStr := matches[2]
+ timeStr := matches[1]
+ level := matches[2]
message := matches[3]
- // 解析时间
- timestamp, err := time.Parse("2006/01/02 15:04:05", timeStr)
+ // 解析时间(使用本地时区)
+ location, err := time.LoadLocation("Asia/Shanghai")
+ if err != nil {
+ return TelegramLogEntry{}, fmt.Errorf("加载时区失败: %v", err)
+ }
+
+ timestamp, err := time.ParseInLocation("2006/01/02 15:04:05", timeStr, location)
if err != nil {
return TelegramLogEntry{}, fmt.Errorf("时间解析失败: %v", err)
}
@@ -203,7 +225,7 @@ func ClearOldTelegramLogs(daysToKeep int) error {
return nil // 日志目录不存在,无需清理
}
- files, err := filepath.Glob(filepath.Join(logDir, "app_*.log"))
+ files, err := filepath.Glob(filepath.Join(logDir, "*.log"))
if err != nil {
return fmt.Errorf("查找日志文件失败: %v", err)
}
diff --git a/web/components/ShareButtons.vue b/web/components/ShareButtons.vue
deleted file mode 100644
index 6358465..0000000
--- a/web/components/ShareButtons.vue
+++ /dev/null
@@ -1,345 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/web/package.json b/web/package.json
index d9ed237..9306b42 100644
--- a/web/package.json
+++ b/web/package.json
@@ -36,8 +36,7 @@
"qr-code-styling": "^1.9.2",
"vfonts": "^0.0.3",
"vue": "^3.3.0",
- "vue-router": "^4.2.0",
- "vue-social-share": "^0.0.3"
+ "vue-router": "^4.2.0"
},
"packageManager": "pnpm@9.13.0+sha512.beb9e2a803db336c10c9af682b58ad7181ca0fbd0d4119f2b33d5f2582e96d6c0d93c85b23869295b765170fbdaa92890c0da6ada457415039769edf3c959efe"
}
diff --git a/web/pages/r/[key].vue b/web/pages/r/[key].vue
index 7a8b9d4..545b9b0 100644
--- a/web/pages/r/[key].vue
+++ b/web/pages/r/[key].vue
@@ -154,14 +154,7 @@
{{ isDetecting ? '检测中' : '链接检测' }}
-
-