reduce logging about db schema initializations during tests

they were a bit too noisy, not helpful
This commit is contained in:
Mechiel Lukkien
2025-01-30 10:21:16 +01:00
parent 807d01ee21
commit f9280b0891
8 changed files with 42 additions and 9 deletions

26
moxvar/reglog.go Normal file
View File

@ -0,0 +1,26 @@
package moxvar
import (
"errors"
"io/fs"
"log/slog"
"os"
"testing"
)
var skipRegisterLogging = testing.Testing()
// RegisterLogger should be used as parameter to bstore.Options.RegisterLogger.
//
// RegisterLogger returns nil when running under test and the database file does
// not yet exist to reduce lots of unhelpful logging, and returns logger log
// otherwise.
func RegisterLogger(path string, log *slog.Logger) *slog.Logger {
if !skipRegisterLogging {
return log
}
if _, err := os.Stat(path); err != nil && errors.Is(err, fs.ErrNotExist) {
return nil
}
return log
}