Skip to content

Commit 5e5b1bc

Browse files
committed
feat(config): add detailed logging for home config changes
- Introduced `logHomeConfigChanges` to compare old and new configs, logging detected differences. - Leveraged `diff.BuildConfigChangeDetails` for structured change detection. - Adjusted logging behavior to enable debug-level logs dynamically when required.
1 parent 15ac7fb commit 5e5b1bc

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

sdk/cliproxy/service.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import (
1717
"github.com/router-for-me/CLIProxyAPI/v7/internal/redisqueue"
1818
"github.com/router-for-me/CLIProxyAPI/v7/internal/registry"
1919
"github.com/router-for-me/CLIProxyAPI/v7/internal/runtime/executor"
20+
"github.com/router-for-me/CLIProxyAPI/v7/internal/util"
2021
"github.com/router-for-me/CLIProxyAPI/v7/internal/watcher"
22+
"github.com/router-for-me/CLIProxyAPI/v7/internal/watcher/diff"
2123
"github.com/router-for-me/CLIProxyAPI/v7/internal/wsrelay"
2224
sdkaccess "github.com/router-for-me/CLIProxyAPI/v7/sdk/access"
2325
sdkAuth "github.com/router-for-me/CLIProxyAPI/v7/sdk/auth"
@@ -606,9 +608,30 @@ func (s *Service) applyHomeOverlay(remoteCfg *config.Config) {
606608
merged.Home = baseCfg.Home
607609
forceHomeRuntimeConfig(&merged)
608610

611+
logHomeConfigChanges(baseCfg, &merged)
609612
s.applyConfigUpdate(&merged)
610613
}
611614

615+
func logHomeConfigChanges(oldCfg, newCfg *config.Config) {
616+
if oldCfg == nil || newCfg == nil || !newCfg.Home.Enabled || (!oldCfg.Debug && !newCfg.Debug) {
617+
return
618+
}
619+
620+
details := diff.BuildConfigChangeDetails(oldCfg, newCfg)
621+
if len(details) == 0 {
622+
return
623+
}
624+
625+
if newCfg.Debug && !log.IsLevelEnabled(log.DebugLevel) {
626+
util.SetLogLevel(newCfg)
627+
}
628+
629+
log.Debugf("home config changes detected:")
630+
for _, detail := range details {
631+
log.Debugf(" %s", detail)
632+
}
633+
}
634+
612635
func (s *Service) startHomeUsageForwarder(ctx context.Context, client *home.Client) {
613636
if s == nil || client == nil {
614637
return

0 commit comments

Comments
 (0)