diff --git a/app.go b/app.go index 035101c..4865486 100644 --- a/app.go +++ b/app.go @@ -1934,7 +1934,13 @@ func (a *App) AddQSO(q qso.QSO) (id int64, err error) { // was redundant with the entry lookup and only slowed logging (a call not yet in // the cache made AddQSO wait on QRZ/HamQTH). If the entry lookup hadn't finished // when you logged (fast CW: type → Enter), the e-mail is simply blank — fine. + insT0 := time.Now() id, err = a.qso.Add(a.ctx, q) + if d := time.Since(insT0); d > 2*time.Second { + // Surface a genuinely slow INSERT (DB lock / overloaded server) — this is the + // value we need when someone reports "logging took N seconds". + applog.Printf("log: SLOW qso insert took %s (call=%s band=%s mode=%s)", d.Round(time.Millisecond), q.Callsign, q.Band, q.Mode) + } if err != nil && db.IsConnLost(err) { // The database is UNREACHABLE (not a data error) — park the QSO in the // offline outbox rather than lose it. Returns id = -1 so the UI can say diff --git a/internal/applog/applog.go b/internal/applog/applog.go index c4bf6d2..7f9e870 100644 --- a/internal/applog/applog.go +++ b/internal/applog/applog.go @@ -47,10 +47,15 @@ func Init(dataDir string) (string, error) { _ = os.Rename(oldLog, logPath) } } - // Truncate if the file grew past ~5MB so we don't accumulate logs - // forever. We keep one file — simple and adequate for diagnostics. - if fi, err := os.Stat(logPath); err == nil && fi.Size() > 5*1024*1024 { - _ = os.Remove(logPath) + // Rotate (don't delete) once the file grows past ~10MB: rename it to + // opslog.log.1 so the PREVIOUS session's log survives. Deleting it outright used + // to erase exactly the diagnostics we needed when a user reported an issue from + // the session that just ended. One generation kept — enough, without unbounded growth. + if fi, err := os.Stat(logPath); err == nil && fi.Size() > 10*1024*1024 { + _ = os.Remove(logPath + ".1") // drop the older generation + if err := os.Rename(logPath, logPath+".1"); err != nil { + _ = os.Remove(logPath) // rename failed (locked?) → fall back to the old behaviour + } } f, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644) if err != nil {