feat: comprehensive INFO/WARN/ERROR logging across all controller modules

Add structured operational logging at INFO, WARN, and ERROR levels to
every controller module. Standardize custom prefixes ([GEO], [SCHED],
[SYNC]) to use [INFO/WARN/ERROR] [module] format. Fix misleveled logs
(WARN->ERROR for data loss scenarios, WARN->INFO for routine operations).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 19:58:27 +01:00
parent 95c821deb2
commit 8e61cd7ec4
44 changed files with 326 additions and 44 deletions
+31 -1
View File
@@ -183,7 +183,7 @@ func Load(path string, logger *log.Logger) (*Settings, error) {
return nil, fmt.Errorf("parsing settings file: %w", err)
}
logger.Printf("[DEBUG] Settings loaded from %s", path)
logger.Printf("[INFO] [settings] Loaded settings from %s", path)
if s.debug {
s.log.Printf("[DEBUG] [settings] loaded: storage_paths=%d integrations=%d pending_events=%d",
len(s.StoragePaths), len(s.Integrations), len(s.PendingEvents))
@@ -218,27 +218,42 @@ func (s *Settings) migrateResticToRsync() {
func (s *Settings) save() error {
data, err := json.MarshalIndent(s, "", " ")
if err != nil {
if s.log != nil {
s.log.Printf("[ERROR] [settings] Failed to save: %v", err)
}
return fmt.Errorf("marshaling settings: %w", err)
}
tmpPath := s.path + ".tmp"
if err := os.MkdirAll(filepath.Dir(s.path), 0755); err != nil {
if s.log != nil {
s.log.Printf("[ERROR] [settings] Failed to save: %v", err)
}
return fmt.Errorf("creating settings dir: %w", err)
}
if err := os.WriteFile(tmpPath, data, 0644); err != nil {
os.Remove(tmpPath) // clean up partial file
if s.log != nil {
s.log.Printf("[ERROR] [settings] Failed to save: %v", err)
}
return fmt.Errorf("writing tmp settings: %w", err)
}
if err := os.Rename(tmpPath, s.path); err != nil {
os.Remove(tmpPath)
if s.log != nil {
s.log.Printf("[ERROR] [settings] Failed to save: %v", err)
}
return fmt.Errorf("renaming settings file: %w", err)
}
if s.debug {
s.log.Printf("[DEBUG] [settings] saved to %s (%d bytes)", s.path, len(data))
}
if s.log != nil {
s.log.Printf("[INFO] [settings] Settings saved")
}
return nil
}
@@ -461,6 +476,9 @@ func (s *Settings) AddStoragePath(sp StoragePath) error {
}
}
s.StoragePaths = append(s.StoragePaths, sp)
if s.log != nil {
s.log.Printf("[INFO] [settings] Added storage path: %s", sp.Path)
}
return s.save()
}
@@ -478,6 +496,9 @@ func (s *Settings) RemoveStoragePath(path string) error {
}
}
s.StoragePaths = kept
if s.log != nil {
s.log.Printf("[INFO] [settings] Removed storage path: %s", path)
}
return s.save()
}
@@ -597,6 +618,9 @@ func (s *Settings) SetDisconnected(path string, disconnected bool, stoppedStacks
if s.debug {
s.log.Printf("[DEBUG] [settings] SetDisconnected path=%q disconnected=%v stopped_stacks=%d", path, disconnected, len(stoppedStacks))
}
if s.log != nil {
s.log.Printf("[INFO] [settings] Node disconnected: %v", disconnected)
}
for i := range s.StoragePaths {
if s.StoragePaths[i].Path == path {
s.StoragePaths[i].Disconnected = disconnected
@@ -707,6 +731,9 @@ func (s *Settings) SetDecommissioned(path, migratedTo string) error {
if s.debug {
s.log.Printf("[DEBUG] [settings] SetDecommissioned path=%q migrated_to=%q", path, migratedTo)
}
if s.log != nil {
s.log.Printf("[INFO] [settings] Node decommissioned")
}
for i := range s.StoragePaths {
if s.StoragePaths[i].Path == path {
s.StoragePaths[i].Decommissioned = true
@@ -842,6 +869,9 @@ func (s *Settings) AddPendingEvent(event PendingEvent) error {
if s.debug {
s.log.Printf("[DEBUG] [settings] AddPendingEvent type=%q severity=%q", event.EventType, event.Severity)
}
if s.log != nil {
s.log.Printf("[INFO] [settings] Added pending event: %s", event.EventType)
}
s.PendingEvents = append(s.PendingEvents, event)
return s.save()
}