Repository: conda/conda

Issue:
importing `conda.cli.python_api` changes root logger
`conda.gateways.logging.initialize_logging` calls `initialize_root_logger` and `initialize_conda_logger` which add custom handlers named "stderr" to the root and "conda" logger and change their levels.
`initialize_logging` gets called when importing `conda.gateways`, `conda.gateways.logging`  and `conda.cli.python_api`.

This is problematic when `conda.cli.python_api.run_command` is incorporated in a program which also uses `logging` (e.g., defining custom formatters, etc.). See:
```python
# uses separate processes to re-init `logging` via `basicConfig`
from multiprocessing import Process


def run(level):
    from logging import basicConfig, getLogger
    awesome_format = "\n>>> AWESOME %(levelname)s: %(message)s"
    basicConfig(format=awesome_format, level=level)
    logger = getLogger(__file__)
    msg = "some message"

    def log():
        logger.debug(msg)
        logger.info(msg)
        logger.warn(msg)
        logger.error(msg)

    log()
    import conda.cli.python_api
    #import conda.gateways
    #import conda.gateways.logging
    log()


for level in ("INFO", "WARN", "ERROR"):
    print("{:-^60}".format(level))
    process = Process(target=run, args=(level,))
    process.start()
    process.join()
    print("\n\n")
```
Output (notice the duplicate `ERROR` messages (with `conda`'s logging format) and omitted `WARNING`s):
```
----------------------------INFO----------------------------

>>> AWESOME INFO: some message

>>> AWESOME WARNING: some message

>>> AWESOME ERROR: some message

>>> AWESOME INFO: No cio_test package found.

>>> AWESOME ERROR: some message
ERROR cli_python_api_logging.py:log(16): some message



----------------------------WARN----------------------------

>>> AWESOME WARNING: some message

>>> AWESOME ERROR: some message

>>> AWESOME ERROR: some message
ERROR cli_python_api_logging.py:log(16): some message



---------------------------ERROR----------------------------

>>> AWESOME ERROR: some message

>>> AWESOME ERROR: some message
ERROR cli_python_api_logging.py:log(16): some message



```


Discussion:

Resolving patch:
diff --git a/conda/gateways/logging.py b/conda/gateways/logging.py
--- a/conda/gateways/logging.py
+++ b/conda/gateways/logging.py
@@ -37,7 +37,7 @@ def filter(self, record):
 
 @memoize
 def initialize_logging():
-    initialize_root_logger()
+    # initialize_root_logger()  # probably don't need to touch the root logger per #5356
     initialize_conda_logger()
 
     formatter = Formatter("%(message)s\n")
@@ -71,7 +71,7 @@ def initialize_conda_logger(level=WARN):
 
 def set_all_logger_level(level=DEBUG):
     formatter = Formatter("%(message)s\n") if level >= INFO else None
-    attach_stderr_handler(level, formatter=formatter)
+    # attach_stderr_handler(level, formatter=formatter)  # probably don't need to touch the root logger per #5356  # NOQA
     attach_stderr_handler(level, 'conda', formatter=formatter)
     attach_stderr_handler(level, 'requests')
     attach_stderr_handler(level, 'requests.packages.urllib3')
@@ -93,4 +93,3 @@ def trace(self, message, *args, **kwargs):
 
 logging.addLevelName(TRACE, "TRACE")
 logging.Logger.trace = trace
-initialize_logging()


Test patch: