Repository: conda/conda

Issue:
Conda prints stuff in stdout even with --json flag on
Conda commands with the `--json` should not print to the console anything unless it is proper json, otherwise assumptions made by parsing clients (Like the Navigator import functionality) break.

Something like

`conda env create -n qatest -f environment.yaml --json`

prints to the standard output

```
Fetching package metadata .........
Solving package specifications: ..........
{"progress": 0, "finished": false, "maxval": 10}
{"name": "openssl", "progress": 0, "finished": false, "maxval": 10}
{"name": "readline", "progress": 1, "finished": false, "maxval": 10}
{"name": "sqlite", "progress": 2, "finished": false, "maxval": 10}
{"name": "tk", "progress": 3, "finished": false, "maxval": 10}
{"name": "xz", "progress": 4, "finished": false, "maxval": 10}
{"name": "zlib", "progress": 5, "finished": false, "maxval": 10}
{"name": "python", "progress": 6, "finished": false, "maxval": 10}
{"name": "setuptools", "progress": 7, "finished": false, "maxval": 10}
{"name": "wheel", "progress": 8, "finished": false, "maxval": 10}
{"name": "pip", "progress": 9, "finished": false, "maxval": 10}
{"progress": 10, "finished": true, "maxval": 10}
```

Conda prints stuff in stdout even with --json flag on
Conda commands with the `--json` should not print to the console anything unless it is proper json, otherwise assumptions made by parsing clients (Like the Navigator import functionality) break.

Something like

`conda env create -n qatest -f environment.yaml --json`

prints to the standard output

```
Fetching package metadata .........
Solving package specifications: ..........
{"progress": 0, "finished": false, "maxval": 10}
{"name": "openssl", "progress": 0, "finished": false, "maxval": 10}
{"name": "readline", "progress": 1, "finished": false, "maxval": 10}
{"name": "sqlite", "progress": 2, "finished": false, "maxval": 10}
{"name": "tk", "progress": 3, "finished": false, "maxval": 10}
{"name": "xz", "progress": 4, "finished": false, "maxval": 10}
{"name": "zlib", "progress": 5, "finished": false, "maxval": 10}
{"name": "python", "progress": 6, "finished": false, "maxval": 10}
{"name": "setuptools", "progress": 7, "finished": false, "maxval": 10}
{"name": "wheel", "progress": 8, "finished": false, "maxval": 10}
{"name": "pip", "progress": 9, "finished": false, "maxval": 10}
{"progress": 10, "finished": true, "maxval": 10}
```



Discussion:

Resolving patch:
diff --git a/conda_env/cli/main.py b/conda_env/cli/main.py
--- a/conda_env/cli/main.py
+++ b/conda_env/cli/main.py
@@ -1,4 +1,7 @@
 from __future__ import print_function, division, absolute_import
+
+from logging import getLogger, CRITICAL
+
 import os
 import sys
 
@@ -66,6 +69,14 @@ def main():
     parser = create_parser()
     args = parser.parse_args()
     context._add_argparse_args(args)
+    if getattr(args, 'json', False):
+        # # Silence logging info to avoid interfering with JSON output
+        # for logger in Logger.manager.loggerDict:
+        #     if logger not in ('fetch', 'progress'):
+        #         getLogger(logger).setLevel(CRITICAL + 1)
+        for logger in ('print', 'dotupdate', 'stdoutlog', 'stderrlog'):
+            getLogger(logger).setLevel(CRITICAL + 1)
+
     return conda_exception_handler(args.func, args, parser)
 
 


Test patch: