feat(logging): add log path configuration and implement logrotate policy

This commit is contained in:
2026-05-22 17:27:57 +08:00
parent 767f26f3c9
commit a2d1dada2c
5 changed files with 62 additions and 5 deletions
+13 -3
View File
@@ -63,7 +63,9 @@ func LoadConfig(configPath string, getInitSystem func() string) error {
global.CurrentConfig.ListenPort = fileConfig.ListenPort
global.CurrentConfig.FrpcPath = fileConfig.FrpcPath
global.CurrentConfig.InstancePath = fileConfig.InstancePath
global.CurrentConfig.LogsPath = fileConfig.LogsPath
global.CurrentConfig.Debug = fileConfig.Debug
global.CurrentConfig.Status.IsLogrotateConfigured = fileConfig.Status.IsLogrotateConfigured
global.CurrentConfig.Watchdog.Enabled = fileConfig.Watchdog.Enabled
global.CurrentConfig.Notification.Enabled = fileConfig.Notification.Enabled
global.CurrentConfig.Notification.Method = fileConfig.Notification.Method
@@ -82,20 +84,28 @@ func LoadConfig(configPath string, getInitSystem func() string) error {
if fileConfig.FrpcPath == "" {
if getInitSystem() == "windows" {
global.CurrentConfig.FrpcPath = "frp_client/frpc.exe"
global.CurrentConfig.FrpcPath = global.CurrentPath + string(os.PathSeparator) + "frp_client" + string(os.PathSeparator) + "frpc.exe"
} else {
global.CurrentConfig.FrpcPath = "/usr/bin/frpc"
global.CurrentConfig.FrpcPath = global.CurrentPath + string(os.PathSeparator) + "frp_client" + string(os.PathSeparator) + "frpc"
}
}
if fileConfig.InstancePath == "" {
global.CurrentConfig.InstancePath = "./configs"
global.CurrentConfig.InstancePath = global.CurrentPath + string(os.PathSeparator) + "configs"
}
if fileConfig.LogsPath == "" {
global.CurrentConfig.LogsPath = global.CurrentPath + string(os.PathSeparator) + "logs"
}
if err := os.MkdirAll(global.CurrentConfig.InstancePath, 0755); err != nil {
return fmt.Errorf("failed to create config directory: %w", err)
}
if err := os.MkdirAll(global.CurrentConfig.LogsPath, 0755); err != nil {
return fmt.Errorf("failed to create log directory: %w", err)
}
postLog.Debug(fmt.Sprintf("Loaded config: %v", global.CurrentConfig))
return nil