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
+6 -5
View File
@@ -2,9 +2,10 @@ package db
import (
"context"
"log/slog"
"os"
"github.com/flowy-live/llink/internal/utils/flog"
"github.com/jackc/pgx/v5/pgxpool"
)
@@ -21,24 +22,24 @@ func Pool() *pgxpool.Pool {
func Init() {
connString := os.Getenv("LLINK_POSTGRES_CONNECTION_URL")
if connString == "" {
slog.Error("must provide LLINK_POSTGRES_CONNECTION_URL in env")
flog.Error("must provide LLINK_POSTGRES_CONNECTION_URL in env")
os.Exit(1)
}
dbpool, err := pgxpool.New(context.Background(), connString)
if err != nil {
slog.Error("unable to create connection pool", "error", err)
flog.Error("unable to create connection pool", "error", err)
os.Exit(1)
}
var greeting string
err = dbpool.QueryRow(context.Background(), "select 'Hello, world!'").Scan(&greeting)
if err != nil {
slog.Error("queryRow failed", "error", err)
flog.Error("queryRow failed", "error", err)
os.Exit(1)
}
slog.Info("successfully connected to database", "greeting", greeting)
flog.Info("successfully connected to database", "greeting", greeting)
db = dbpool
}