MCPcopy Index your code
hub / github.com/jetify-com/devbox / logRunFunc

Method logRunFunc

nix/command.go:282–299  ·  view source on GitHub ↗

logRunFunc logs the start and exit of c.execCmd. It adjusts the source attribute of the log record to point to the caller of c.CombinedOutput, c.Output, or c.Run. This assumes a specific stack depth, so do not call logRunFunc from other methods or functions.

(ctx context.Context)

Source from the content-addressed store, hash-verified

280// c.Output, or c.Run. This assumes a specific stack depth, so do not call
281// logRunFunc from other methods or functions.
282func (c *Cmd) logRunFunc(ctx context.Context) func() {
283 logger := c.logger()
284 if !logger.Enabled(ctx, slog.LevelDebug) {
285 return func() {}
286 }
287
288 var pcs [1]uintptr
289 runtime.Callers(3, pcs[:]) // skip Callers, logRunFunc, CombinedOutput/Output/Run
290 r := slog.NewRecord(time.Now(), slog.LevelDebug, "nix command starting", pcs[0])
291 r.Add("cmd", c)
292 _ = logger.Handler().Handle(ctx, r)
293
294 return func() {
295 r := slog.NewRecord(time.Now(), slog.LevelDebug, "nix command exited", pcs[0])
296 r.Add("cmd", c)
297 _ = logger.Handler().Handle(ctx, r)
298 }
299}
300
301// Args is a slice of [Cmd] arguments.
302type Args []any

Callers 3

CombinedOutputMethod · 0.95
OutputMethod · 0.95
RunMethod · 0.95

Calls 3

loggerMethod · 0.95
EnabledMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected