From 040fb548f0f6a653f81ed8c3807a22606e5d616c Mon Sep 17 00:00:00 2001 From: Kristaps Kaupe Date: Thu, 23 Sep 2021 09:27:45 +0300 Subject: [PATCH] Fix JSON output when stdout is not a terminal When output is redirected, colourizer is not used, so character replacements aren't needed too. --- jmbase/jmbase/support.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/jmbase/jmbase/support.py b/jmbase/jmbase/support.py index 1035419..a56eb7b 100644 --- a/jmbase/jmbase/support.py +++ b/jmbase/jmbase/support.py @@ -170,11 +170,12 @@ def jmprint(msg, level="info"): if not level in jm_color_map.keys(): raise Exception("Unsupported formatting") - # .colorize_message function does a .format() on the string, - # which does not work with string-ified json; this should - # result in output as intended: - msg = msg.replace('{', '{{') - msg = msg.replace('}', '}}') + if sys.stdout.isatty(): + # .colorize_message function does a .format() on the string, + # which does not work with string-ified json; this should + # result in output as intended: + msg = msg.replace('{', '{{') + msg = msg.replace('}', '}}') fmtfn = eval(level) fmtd_msg = fmtfn(msg)