mirror of
https://github.com/mjl-/mox.git
synced 2025-07-14 18:14:38 +03:00
reduce logging about db schema initializations during tests
they were a bit too noisy, not helpful
This commit is contained in:
26
moxvar/reglog.go
Normal file
26
moxvar/reglog.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user