feat: comprehensive debug logging across all controller modules

Add detailed [DEBUG] logging to every controller module when
logging.level is set to "debug". Each module with stateful debug
uses SetDebug(bool) wired from main.go. Covers stacks, backup,
cloudflare, integrations, system, monitor, settings, scheduler,
web handlers, storage, metrics, API, selfupdate, and assets.

Also includes the app export/import (.fab bundles) feature from
v0.32.0 and its debug page integration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 18:14:43 +01:00
parent f6caea8067
commit 95c821deb2
54 changed files with 5015 additions and 82 deletions
@@ -44,12 +44,26 @@ type Scheduler struct {
mu sync.Mutex
jobs []*Job
logger *log.Logger
debug bool
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
started bool
}
// SetDebug enables or disables debug logging.
func (s *Scheduler) SetDebug(on bool) {
s.mu.Lock()
defer s.mu.Unlock()
s.debug = on
}
func (s *Scheduler) dbg(format string, args ...interface{}) {
if s.debug {
s.logger.Printf("[DEBUG] [sched] "+format, args...)
}
}
// New creates a new Scheduler.
func New(logger *log.Logger) *Scheduler {
return &Scheduler{
@@ -75,6 +89,7 @@ func (s *Scheduler) Every(name string, interval time.Duration, fn JobFunc) {
}
s.jobs = append(s.jobs, job)
s.logger.Printf("[SCHED] Registered periodic job: %s (every %s)", name, interval)
s.dbg("periodic job registered: name=%q interval=%s totalJobs=%d", name, interval, len(s.jobs))
if s.started {
s.wg.Add(1)
@@ -103,6 +118,7 @@ func (s *Scheduler) Daily(name string, timeStr string, fn JobFunc) {
nextRun := nextDailyRun(timeStr)
s.logger.Printf("[SCHED] Daily job %s scheduled for %s", name, nextRun.Format("2006-01-02 15:04 MST"))
s.dbg("daily job registered: name=%q schedule=%q nextRun=%s totalJobs=%d", name, timeStr, nextRun.Format(time.RFC3339), len(s.jobs))
if s.started {
s.wg.Add(1)
@@ -132,6 +148,23 @@ func (s *Scheduler) Start(ctx context.Context) {
}
s.logger.Printf("[SCHED] Scheduler started with %d jobs", len(s.jobs))
s.dbg("scheduler started: periodic=%d daily=%d", func() int {
n := 0
for _, j := range s.jobs {
if j.Interval > 0 {
n++
}
}
return n
}(), func() int {
n := 0
for _, j := range s.jobs {
if j.Schedule != "" {
n++
}
}
return n
}())
s.mu.Unlock()
}
@@ -200,10 +233,13 @@ func (s *Scheduler) runDailyJob(job *Job) {
waitDuration = 0
}
s.dbg("daily job %s: next run at %s (waiting %s)", job.Name, nextRun.Format("2006-01-02 15:04:05 MST"), waitDuration.Round(time.Second))
timer := time.NewTimer(waitDuration)
select {
case <-s.ctx.Done():
timer.Stop()
s.dbg("daily job %s: context cancelled, stopping", job.Name)
return
case <-timer.C:
s.executeJob(job, false)
@@ -241,6 +277,7 @@ func (s *Scheduler) executeJob(job *Job, quiet bool) {
if !quiet {
s.logger.Printf("[SCHED] Running job: %s", job.Name)
}
s.dbg("job %s: execution starting", job.Name)
start := time.Now()
err := job.Fn(s.ctx)
@@ -253,9 +290,11 @@ func (s *Scheduler) executeJob(job *Job, quiet bool) {
if err != nil {
s.logger.Printf("[WARN] Job %s failed: %v (took %s)", job.Name, err, elapsed.Round(time.Millisecond))
s.dbg("job %s: failed after %s: %v", job.Name, elapsed.Round(time.Millisecond), err)
} else if !quiet {
s.logger.Printf("[SCHED] Job %s completed (took %s)", job.Name, elapsed.Round(time.Millisecond))
}
s.dbg("job %s: finished in %s (err=%v)", job.Name, elapsed.Round(time.Millisecond), err)
}
// parseDailyTime parses "HH:MM" and returns hour and minute.