package fog import ( "context" "github.com/go-logr/logr" ) // FromContext returns a logger with predefined values from a [context.Context]. // If one doesn't exist, a default logger is instantiated and returned. // // This is a thin wrapper around [github.com/go-logr/logr.FromContext] func FromContext(ctx context.Context, keysAndValues ...interface{}) logr.Logger { if ctx != nil { if logger, err := logr.FromContext(ctx); err == nil { return logger.WithValues(keysAndValues...) } } return New().WithValues(keysAndValues...) } // IntoContext takes a context and sets the logger as one of its values. // Use the [FromContext] function to retrieve the logger. // // This is a thin wrapper around [github.com/go-logr/logr.IntoContext] func IntoContext(ctx context.Context, log logr.Logger) context.Context { return logr.NewContext(ctx, log) }