Repository: pypa/pip

Issue:
Pip upgrade prompt is not sent to stderr anymore
### Description

Hello there! 👋 

This is my first bug report to pip 😃 I've written Python for more than 10 years and it's always been a pleasure to install packages with `pip`. We, at Mozilla, use Python intensively for our CI/CD and pip is the cornerstone of our package management. Today, we ran into an issue that blocked [our entire CI/CD](https://bugzilla.mozilla.org/show_bug.cgi?id=1780539). We parse the output of `pip freeze` and today, some lines couldn't be parsed. These were lines about a pip upgrade.

After looking into the pip code, we realized this fairly recent PR https://github.com/pypa/pip/pull/10959 changed the formatting of the upgrade prompt, but also it now redirects the prompt to `stdout` instead of `stderr`. Based on the patch, I get the feeling this is unexpected behavior.

There's been 4 releases since this PR got merged. There are 2 reasons why we just noticed it today:
 1. I upgraded pip in our infra from 21.1.3 to 22.1.2, 12 days ago
 2. 22.2 got released 3 hours ago. 

Shoutout to @jcristau who was instrumental in narrowing down the bug to https://github.com/pypa/pip/pull/10959

### Expected behavior

For the sake of remaining parseable, I believe the upgrade prompt should remain in `stderr`. I'm happy to discuss this though 🙂 

### pip version

21.1

### Python version

N/A

### OS

N/A

### How to Reproduce

Steps to reproduce: 
 1. `VERSION='22.0.4'; pip install "$VERSION" && pip list --format freeze > "$VERSION".stdout.txt 2> "$VERSION".stderr.txt`
 2. Change the version number to `22.1.2` and rerun the same command
 3. `head *.txt`

See the output below: it shows there's nothing anymore in stderr and the prompt got moved to stdout.

### Output

```shell
==> 22.0.4.stderr.txt <==
WARNING: You are using pip version 22.0.4; however, version 22.2 is available.
You should consider upgrading via the '/private/tmp/pip/.env/bin/python -m pip install --upgrade pip' command.

==> 22.0.4.stdout.txt <==
pip==22.0.4
setuptools==62.6.0
wheel==0.37.1

==> 22.1.2.stderr.txt <==

==> 22.1.2.stdout.txt <==
pip==22.1.2
setuptools==62.6.0
wheel==0.37.1

[notice] A new release of pip available: 22.1.2 -> 22.2
[notice] To update, run: pip install --upgrade pip
```


### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:
cc @pradyunsg @pfmoore @uranusjr 
Looks like a bug in the previous version that is being revealed by today's release.
Agreed. A PR to change the output destination of this message back to stderr would be welcomed.
FWIW, I confirm the issue on Ubuntu, Windows and macOS, as in my [`meta-package-manager`](https://github.com/kdeldycke/meta-package-manager) tool, any call to `pip` commands with a `--format=json` option will end up with output to `stdout` that is unparseable by a `json.loads()` method (as done here: https://github.com/kdeldycke/meta-package-manager/blob/main/meta_package_manager/managers/pip.py#L102-L105 ).

Resolving patch:
diff --git a/src/pip/_internal/self_outdated_check.py b/src/pip/_internal/self_outdated_check.py
--- a/src/pip/_internal/self_outdated_check.py
+++ b/src/pip/_internal/self_outdated_check.py
@@ -233,7 +233,7 @@ def pip_self_version_check(session: PipSession, options: optparse.Values) -> Non
             ),
         )
         if upgrade_prompt is not None:
-            logger.info("[present-rich] %s", upgrade_prompt)
+            logger.warning("[present-rich] %s", upgrade_prompt)
     except Exception:
         logger.warning("There was an error checking the latest version of pip.")
         logger.debug("See below for error", exc_info=True)


Test patch: