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