diag: log slow QSO inserts (>2s) with call/band/mode; rotate the app log to .1 at 10MB instead of deleting it, so the previous session's diagnostics survive

This commit is contained in:
2026-07-21 16:24:50 +02:00
parent aa537f9eea
commit 40d0ca57c3
2 changed files with 15 additions and 4 deletions
+6
View File
@@ -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
+9 -4
View File
@@ -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 {