Skip to content

Commit 61715ae

Browse files
author
nareshwart
committed
fix
1 parent a199827 commit 61715ae

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/main/java/com/devopsdemo/utilities/LoggerStackTraceUtil.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99
*/
1010
public class LoggerStackTraceUtil {
1111

12+
/**
13+
* Returns the stack trace of an exception as a string.
14+
* @param ex the exception
15+
* @return the stack trace string
16+
*/
17+
public static String getStackTrace(Exception ex) {
18+
if (ex == null) return "";
19+
StringBuilder sb = new StringBuilder();
20+
for (StackTraceElement elem : ex.getStackTrace()) {
21+
sb.append(elem.toString()).append(System.lineSeparator());
22+
}
23+
return sb.toString();
24+
}
25+
1226
private static final Logger LOG = LoggerFactory.getLogger(LoggerStackTraceUtil.class);
1327
private final int maxCount = 3;
1428

0 commit comments

Comments
 (0)