Features: - CLI structure with verbs and resources - Application config and parameters - Output formatters - Initial resource: dishes Reviewed-on: #1 Co-authored-by: bdoerfchen <git@bissendorf.co> Co-committed-by: bdoerfchen <git@bissendorf.co>
24 lines
420 B
Go
24 lines
420 B
Go
package jlog
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
)
|
|
|
|
type ctxKey string
|
|
|
|
const ctxkeyLogger ctxKey = "jlog:logger"
|
|
|
|
func FromContext(ctx context.Context) *slog.Logger {
|
|
logger, exists := ctx.Value(ctxkeyLogger).(*slog.Logger)
|
|
if !exists {
|
|
return New(slog.LevelInfo)
|
|
}
|
|
|
|
return logger
|
|
}
|
|
|
|
func ContextWith(ctx context.Context, logger *slog.Logger) context.Context {
|
|
return context.WithValue(ctx, ctxkeyLogger, logger)
|
|
}
|