@@ -1141,11 +1141,7 @@ def _monitor_process(
11411141 elif stdout_destination == "file" and output_stderr :
11421142 _stdout .write (output_stderr .encode (encoding , errors = errors ))
11431143
1144- logger .debug (
1145- 'Command "{}" returned with exit code "{}". Command output was:\n {}' .format (
1146- command , exit_code , to_encoding (output_stdout , error_encoding , errors )
1147- )
1148- )
1144+ logger .debug ('Command "{}" returned with exit code "{}"' .format (command , exit_code ))
11491145 except subprocess .CalledProcessError as exc :
11501146 exit_code = exc .returncode
11511147 try :
@@ -1162,13 +1158,12 @@ def _monitor_process(
11621158
11631159 if not silent :
11641160 logger_fn (
1165- 'Command "{}" failed with{} exit code "{}". Command output was: ' .format (
1161+ 'Command "{}" failed with{} exit code "{}"' .format (
11661162 command ,
11671163 valid_exit_codes_msg ,
11681164 exc .returncode ,
11691165 )
11701166 )
1171- logger_fn (output_stdout )
11721167 except FileNotFoundError as exc :
11731168 message = 'Command "{}" failed, file not found: {}' .format (
11741169 command , to_encoding (exc .__str__ (), error_encoding , errors )
@@ -1234,14 +1229,6 @@ def _monitor_process(
12341229 if stderr_destination == "file" :
12351230 _stderr .close ()
12361231
1237- stdout_output = to_encoding (output_stdout , error_encoding , errors )
1238- if stdout_output :
1239- logger .debug ("STDOUT: " + stdout_output )
1240- if stderr_destination not in ["stdout" , None ]:
1241- stderr_output = to_encoding (output_stderr , error_encoding , errors )
1242- if stderr_output :
1243- logger .debug ("STDERR: " + stderr_output )
1244-
12451232 # Make sure we send a simple queue end before leaving to make sure any queue read process will stop regardless
12461233 # of command_runner state (useful when launching with queue and method poller which isn't supposed to write queues)
12471234 if not no_close_queues :
@@ -1264,6 +1251,17 @@ def _monitor_process(
12641251 ):
12651252 output_stderr = None
12661253
1254+ stdout_output = to_encoding (output_stdout , error_encoding , errors )
1255+ if stdout_output :
1256+ logger .debug ("STDOUT: " + stdout_output )
1257+ if stderr_destination not in ["stdout" , None ]:
1258+ stderr_output = to_encoding (output_stderr , error_encoding , errors )
1259+ if stderr_output and not silent :
1260+ if exit_code == 0 or (valid_exit_codes and valid_exit_codes is True or exit_code in valid_exit_codes ):
1261+ logger .debug ("STDERR: " + stderr_output )
1262+ else :
1263+ logger .error ("STDERR: " + stderr_output )
1264+
12671265 if on_exit :
12681266 logger .debug ("Running on_exit callable." )
12691267 on_exit ()
0 commit comments