32de5b26a8
Blue-green zero-downtime deploys, promote flow validation. Dual auth: local (bcrypt + JWT) and OAuth2/OIDC (any provider). Auth middleware, login page, auth settings UI. Structured logging (slog JSON), config export to YAML. Graceful shutdown with deploy draining. Multi-stage Dockerfile and production docker-compose.yml. Swap phase order: Volumes & Env before UI Polish.
35 lines
900 B
Go
35 lines
900 B
Go
package logging
|
|
|
|
import (
|
|
"io"
|
|
"log/slog"
|
|
"os"
|
|
)
|
|
|
|
// Setup initializes the global structured JSON logger.
|
|
// It replaces the default slog handler with a JSON handler writing to stdout.
|
|
func Setup() {
|
|
handler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
|
Level: slog.LevelInfo,
|
|
})
|
|
slog.SetDefault(slog.New(handler))
|
|
}
|
|
|
|
// SetupWithWriter initializes the global structured JSON logger writing to the given writer.
|
|
func SetupWithWriter(w io.Writer) {
|
|
handler := slog.NewJSONHandler(w, &slog.HandlerOptions{
|
|
Level: slog.LevelInfo,
|
|
})
|
|
slog.SetDefault(slog.New(handler))
|
|
}
|
|
|
|
// DeployContext returns a logger enriched with deploy-specific attributes.
|
|
func DeployContext(project, stage, tag, instanceID string) *slog.Logger {
|
|
return slog.With(
|
|
slog.String("project", project),
|
|
slog.String("stage", stage),
|
|
slog.String("tag", tag),
|
|
slog.String("instance_id", instanceID),
|
|
)
|
|
}
|