fix(logs): limit Xray log growth (#5840)

* Limit Xray log growth

* Apply suggestion from @github-actions[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Apply suggestion from @github-actions[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Mahyar Dana <dana.mahyar76@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Rouzbeh†
2026-07-08 01:03:34 +03:30
committed by GitHub
parent 9b91f0f42e
commit 15faec6258
5 changed files with 120 additions and 37 deletions
+15 -7
View File
@@ -66,8 +66,7 @@ func GetIPLimitBannedPrevLogPath() string {
return config.GetLogFolder() + "/3xipl-banned.prev.log"
}
// GetAccessLogPath reads the Xray config and returns the access log file path.
func GetAccessLogPath() (string, error) {
func getLogPath(key string) (string, error) {
config, err := os.ReadFile(GetConfigPath())
if err != nil {
logger.Warningf("Failed to read configuration file: %s", err)
@@ -81,16 +80,25 @@ func GetAccessLogPath() (string, error) {
return "", err
}
if jsonConfig["log"] != nil {
jsonLog := jsonConfig["log"].(map[string]any)
if jsonLog["access"] != nil {
accessLogPath := jsonLog["access"].(string)
return accessLogPath, nil
if jsonLog, ok := jsonConfig["log"].(map[string]any); ok {
if logPath, ok := jsonLog[key].(string); ok {
return logPath, nil
}
}
return "", err
}
// GetAccessLogPath reads the Xray config and returns the access log file path.
func GetAccessLogPath() (string, error) {
return getLogPath("access")
}
// GetErrorLogPath reads the Xray config and returns the error log file path.
// GetErrorLogPath reads the Xray config and returns the error log file path.
func GetErrorLogPath() (string, error) {
return getLogPath("error")
}
// stopProcess calls Stop on the given Process instance.
func stopProcess(p *Process) {
_ = p.Stop()