infra: add logging wrapping

Resolves issues with gcp cloud logging quirks such as field names
This commit is contained in:
Arjun Patel
2026-05-27 15:49:27 -07:00
parent e804cee229
commit 563c91e7d5
30 changed files with 347 additions and 250 deletions
+9 -8
View File
@@ -3,10 +3,11 @@ package testhelper
import (
"context"
"fmt"
"log/slog"
"os"
"time"
"github.com/flowy-live/llink/internal/utils/flog"
"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"
@@ -39,20 +40,20 @@ func SetupTestDB() *pgxpool.Pool {
),
)
if err != nil {
slog.Error("failed to start postgres container", "error", err)
flog.Error("failed to start postgres container", "error", err)
os.Exit(1)
}
// Get connection URL
host, err := container.Host(ctx)
if err != nil {
slog.Error("failed to get container host", "error", err)
flog.Error("failed to get container host", "error", err)
os.Exit(1)
}
port, err := container.MappedPort(ctx, "5432")
if err != nil {
slog.Error("failed to get container port", "error", err)
flog.Error("failed to get container port", "error", err)
os.Exit(1)
}
@@ -62,20 +63,20 @@ func SetupTestDB() *pgxpool.Pool {
// Run migrations
m, err := migrate.New("file://../../migrations", connectionURL)
if err != nil {
slog.Error("failed to create migrate instance", "error", err)
flog.Error("failed to create migrate instance", "error", err)
os.Exit(1)
}
defer m.Close()
if err := m.Up(); err != nil && err != migrate.ErrNoChange {
slog.Error("failed to run migrations", "error", err)
flog.Error("failed to run migrations", "error", err)
os.Exit(1)
}
// Create connection pool
dbPool, err = pgxpool.New(ctx, connectionURL)
if err != nil {
slog.Error("failed to create connection pool", "error", err)
flog.Error("failed to create connection pool", "error", err)
os.Exit(1)
}
@@ -89,7 +90,7 @@ func TeardownTestDB() {
}
if container != nil {
if err := container.Terminate(ctx); err != nil {
slog.Error("failed to terminate container", "error", err)
flog.Error("failed to terminate container", "error", err)
}
}
}