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)
| 280 | // c.Output, or c.Run. This assumes a specific stack depth, so do not call |
| 281 | // logRunFunc from other methods or functions. |
| 282 | func (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. |
| 302 | type Args []any |