code: func attachOutputForLogging(c context.Context, l logging.Level, cmd *exec.Cmd) func(context.Context, logging.Level) {
  	if logging.IsLogging(c, logging.Info) {
  		logging.Infof(c, "Running Python command (cwd=%s): %s",
  			cmd.Dir, strings.Join(cmd.Args, " "))
  	}
  
  	var out io.Writer
  	var buf bytes.Buffer
  	if logging.IsLogging(c, l) {
  		// If we're logging, redirect all process output to STDERR (same as logger
  		// uses).
  		out = os.Stderr
  	} else {
  		out = &buf
  	}
  
  	if cmd.Stdout == nil {
  		// STDOUT will be sent to our output channel, since this logging for
  		// debugging, not actual functional process output.
  		cmd.Stdout = out
  	}
  	if cmd.Stderr == nil {
  		cmd.Stderr = out
  	}
  
  	// Do not dump any additional error output.
  	return func(c context.Context, l logging.Level) {
  		logging.Logf(c, l, "Command (cwd=%s): %s\nProcess output:\n%s\nEnvironment:\n%s",
  			cmd.Dir, cmd.Args, buf.Bytes(), strings.Join(cmd.Env, "\n"))
  	}
  }
docs: // attachOutputForLogging modifies the supplied cmd's Stdout and Stderr fields
  // to output appropriately, assuming it isn't otherwise configured.
  //
  // If we are logging at level l, the process's Stdout and Stderr will be
  // directly connected to STDERR
  //
  // This will return a callback that can be invoked to dump any buffered process
  // output at the specified logging level.