Skip to content

Commit 9b30b2c

Browse files
committed
+ support DCM_AGENT_SUPRESS_EXCEPTION_STACK option
1 parent 37e5a84 commit 9b30b2c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

library/src/main/java/com/alibaba/dcm/agent/DcmAgent.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
public class DcmAgent {
2020
static final String FILE = "file";
21+
static final String DCM_AGENT_SUPRESS_EXCEPTION_STACK = "DCM_AGENT_SUPRESS_EXCEPTION_STACK";
2122
static final String DCM_AGENT_SUCCESS_MARK_LINE = "!!DCM SUCCESS!!";
2223

2324
public static void agentmain(String agentArgument) throws Exception {
@@ -75,8 +76,14 @@ public static void agentmain(String agentArgument) throws Exception {
7576
} catch (Exception e) {
7677
allSuccess = false;
7778
final String exString = throwable2StackString(e);
79+
final String sdtoutExString;
80+
if (isDcmAgentSupressExceptionStack()) {
81+
sdtoutExString = e.toString();
82+
} else {
83+
sdtoutExString = exString;
84+
}
7885

79-
System.out.printf("%s: Error to do action %s %s, cause: %s%n", DcmAgent.class.getName(), action, argumentString, exString);
86+
System.out.printf("%s: Error to do action %s %s, cause: %s%n", DcmAgent.class.getName(), action, argumentString, sdtoutExString);
8087
if (filePrinter != null) {
8188
filePrinter.printf("Error to do action %s %s, cause: %s%n", action, argumentString, exString);
8289
}
@@ -186,6 +193,24 @@ static Object[] convertStringArray2Arguments(String action, String[] arguments,
186193
return methodArgs;
187194
}
188195

196+
static boolean isDcmAgentSupressExceptionStack() {
197+
String supressException = getConfig(DCM_AGENT_SUPRESS_EXCEPTION_STACK);
198+
if (supressException == null) return false;
199+
200+
supressException = supressException.trim();
201+
if (supressException.length() == 0) return false;
202+
203+
return "true".equalsIgnoreCase(supressException);
204+
}
205+
206+
static String getConfig(String name) {
207+
String var = System.getenv(name);
208+
if (var == null || var.trim().length() == 0) {
209+
var = System.getProperty(name);
210+
}
211+
return var;
212+
}
213+
189214
static void printResult(String action, Object result, PrintWriter writer) {
190215
if (writer == null) {
191216
return;

0 commit comments

Comments
 (0)