searcherside/infrastructure/logging/context.go
Peter Kurfer 9ea9a8f658
Some checks failed
Go build / build (push) Failing after 1m58s
feat: continue basic setup
- setup ent scheme
- add command to create users
- document API
- add helpers to create migrations
- add command to run migrations
- add basic compose file
2024-06-19 21:19:37 +02:00

20 lines
395 B
Go

package logging
import (
"context"
"log/slog"
)
var loggerKey struct{}
func ContextWithLogger(ctx context.Context, logger *slog.Logger) context.Context {
return context.WithValue(ctx, loggerKey, logger)
}
func GetLogger(ctx context.Context) *slog.Logger {
contextLogger := ctx.Value(loggerKey).(*slog.Logger)
if contextLogger == nil {
return slog.Default()
}
return contextLogger
}