Files
tiny-forge/internal/logging/logger.go
alexei.dolgolyov 32de5b26a8 feat(docker-watcher): phase 12 - hardening
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.
2026-03-27 23:20:56 +03:00

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),
)
}