liyafan82 commented on a change in pull request #8220: 
[FLINK-12259][flink-clients]Improve debuggability of method invocatio…
URL: https://github.com/apache/flink/pull/8220#discussion_r277193491
 
 

 ##########
 File path: 
flink-clients/src/main/java/org/apache/flink/client/program/OptimizerPlanEnvironment.java
 ##########
 @@ -74,9 +76,11 @@ public FlinkPlan getOptimizedPlan(PackagedProgram prog) 
throws ProgramInvocation
                PrintStream originalOut = System.out;
                PrintStream originalErr = System.err;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-               System.setOut(new PrintStream(baos));
+               TeeOutputStream combinedStdOut = new 
TeeOutputStream(originalOut, baos);
+               System.setOut(new PrintStream(combinedStdOut));
                ByteArrayOutputStream baes = new ByteArrayOutputStream();
-               System.setErr(new PrintStream(baes));
+               TeeOutputStream combinedStdErr = new 
TeeOutputStream(originalErr, baes);
 
 Review comment:
   > Do we need to close these streams? Additionally, its not clear to me why 
we need to trap the output. It seems to only be used for the exception at line 
109. Couldn't the client just refer to the logs instead?
   
   Thank you for your comments. 
   It depends on the underlying streams to decide whether we need to close the 
streams. The underlying steams are stdout/stderr, and byte array streams. So it 
is OK not to close them. However, for the sake of completeness, it is better to 
close them.
   The purpose of the trapping is that the output will be both encoded in the 
exception, and printed in the console, so that the user can easily see it. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to