MCPcopy
hub / github.com/zarf-dev/zarf / From

Function From

src/pkg/logger/logger.go:216–235  ·  view source on GitHub ↗

From takes a context and reads out a *slog.Logger. If From does not find a value it will return a discarding logger similar to log-format "none".

(ctx context.Context)

Source from the content-addressed store, hash-verified

214// From takes a context and reads out a *slog.Logger. If From does not find a value it will return a discarding logger
215// similar to log-format "none".
216func From(ctx context.Context) *slog.Logger {
217 // Check that we have a ctx
218 if ctx == nil {
219 return newDiscard()
220 }
221 // Grab value from key
222 log := ctx.Value(defaultCtxKey)
223 if log == nil {
224 return newDiscard()
225 }
226
227 // Ensure our value is a *slog.Logger before we cast.
228 switch l := log.(type) {
229 case *slog.Logger:
230 return l
231 default:
232 // Not reached
233 panic(fmt.Sprintf("unexpected value type on context key: %T", log))
234 }
235}
236
237// newDiscard returns a logger without any settings that goes to io.Discard
238func newDiscard() *slog.Logger {

Callers 15

DevDeployFunction · 0.92
PackageDigestFunction · 0.92
UpdateSchemaFunction · 0.92
UpdateImagesFunction · 0.92
RemoveFunction · 0.92
PullFunction · 0.92
findImagesFunction · 0.92
appendToImageMapOCIRepoFunction · 0.92
GenerateFunction · 0.92
CreateFunction · 0.92

Calls 1

newDiscardFunction · 0.85

Tested by 1

TestContextFunction · 0.68