feat: enable ContractPrinter by isDebug

This commit is contained in:
garvey-wong 2022-06-10 11:48:32 +08:00
parent 3db9180ceb
commit 540fbd65f8

View File

@ -22,6 +22,7 @@ import org.bdware.sc.util.JsonUtil;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
@ -285,7 +286,8 @@ public class ContractClient {
PrintStream printStream = new PrintStream(process.getOutputStream()); PrintStream printStream = new PrintStream(process.getOutputStream());
printStream.println("CP PID:" + pid); printStream.println("CP PID:" + pid);
printStream.close(); printStream.close();
Scanner sc = new Scanner(process.getInputStream()); InputStream processInputStream = process.getInputStream();
Scanner sc = new Scanner(processInputStream);
String status = null; String status = null;
while (sc.hasNext()) { while (sc.hasNext()) {
status = sc.nextLine(); status = sc.nextLine();
@ -315,10 +317,16 @@ public class ContractClient {
ContractManager.cPort.updateDb(port, true); ContractManager.cPort.updateDb(port, true);
get = new SocketGet("127.0.0.1", port); get = new SocketGet("127.0.0.1", port);
get.syncGet("", "setDBInfo", ContractManager.dbPath); get.syncGet("", "setDBInfo", ContractManager.dbPath);
if (isDebug) {
String tagA = (ps == System.out ? "[Contract_" + port + "_out] " : ""); String tagA = (ps == System.out ? "[Contract_" + port + "_out] " : "");
String tagB = (ps == System.out ? "[Contract_" + port + "_err] " : ""); String tagB = (ps == System.out ? "[Contract_" + port + "_err] " : "");
outputTracer.track(process, sc, tagA, ps); outputTracer.track(process, sc, tagA, ps);
errorTracer.track(process, new Scanner(process.getErrorStream()), tagB, ps); errorTracer.track(process, new Scanner(process.getErrorStream()), tagB, ps);
} else {
// 关闭流否则缓冲区打满会阻塞进程
processInputStream.close();
sc.close();
}
get.syncGet("", "registerMangerPort", String.valueOf(ContractManager.cPort.getCMPort())); get.syncGet("", "registerMangerPort", String.valueOf(ContractManager.cPort.getCMPort()));
if (isBundlePath(contractMeta.contract.getScriptStr())) { if (isBundlePath(contractMeta.contract.getScriptStr())) {