feat: add server log file management to performance settings

Add API endpoints (GET/DELETE /api/performance/logs) to list and clean up
server log files by count or by age. Track the active log file path in
the logger to prevent deleting the currently open log. Add a management
UI section in the performance settings page with log directory info,
file statistics, and cleanup controls. Includes i18n translations for
all supported languages (en, fr, ja, ru, vi, zh-CN, zh-TW).
This commit is contained in:
RedwindA
2026-03-21 20:06:49 +08:00
parent 42846c692e
commit e904579a5b
11 changed files with 467 additions and 0 deletions

View File

@@ -29,6 +29,15 @@ const maxLogCount = 1000000
var logCount int
var setupLogLock sync.Mutex
var setupLogWorking bool
var currentLogPath string
var currentLogPathMu sync.RWMutex
var currentLogFile *os.File
func GetCurrentLogPath() string {
currentLogPathMu.RLock()
defer currentLogPathMu.RUnlock()
return currentLogPath
}
func SetupLogger() {
defer func() {
@@ -48,8 +57,16 @@ func SetupLogger() {
if err != nil {
log.Fatal("failed to open log file")
}
currentLogPathMu.Lock()
oldFile := currentLogFile
currentLogPath = logPath
currentLogFile = fd
gin.DefaultWriter = io.MultiWriter(os.Stdout, fd)
gin.DefaultErrorWriter = io.MultiWriter(os.Stderr, fd)
currentLogPathMu.Unlock()
if oldFile != nil {
_ = oldFile.Close()
}
}
}