Suppress verbose vips logging output

Initialize libvips with LogLevelError to prevent info-level messages
from polluting the JSON log stream.
This commit is contained in:
2026-01-08 16:13:52 -08:00
parent 3849128c45
commit 982accd549
2 changed files with 14 additions and 1 deletions

View File

@@ -6,10 +6,22 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"sync"
"github.com/davidbyttow/govips/v2/vips" "github.com/davidbyttow/govips/v2/vips"
) )
// vipsOnce ensures vips is initialized exactly once.
var vipsOnce sync.Once
// initVips initializes libvips with quiet logging.
func initVips() {
vipsOnce.Do(func() {
vips.LoggingSettings(nil, vips.LogLevelError)
vips.Startup(nil)
})
}
// MaxInputDimension is the maximum allowed width or height for input images. // MaxInputDimension is the maximum allowed width or height for input images.
// Images larger than this are rejected to prevent DoS via decompression bombs. // Images larger than this are rejected to prevent DoS via decompression bombs.
const MaxInputDimension = 8192 const MaxInputDimension = 8192
@@ -25,6 +37,7 @@ type ImageProcessor struct{}
// NewImageProcessor creates a new image processor. // NewImageProcessor creates a new image processor.
func NewImageProcessor() *ImageProcessor { func NewImageProcessor() *ImageProcessor {
initVips()
return &ImageProcessor{} return &ImageProcessor{}
} }

View File

@@ -15,7 +15,7 @@ import (
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
vips.Startup(nil) initVips()
code := m.Run() code := m.Run()
vips.Shutdown() vips.Shutdown()
os.Exit(code) os.Exit(code)