Skip to content

Commit f16f7cd

Browse files
authored
Add stack trace to logger DTO (#4732)
Signed-off-by: Chris Jackson <[email protected]>
1 parent 5c42be4 commit f16f7cd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/log/LogDTO.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ public class LogDTO implements Comparable<LogDTO> {
3030
public Date timestamp;
3131
public long unixtime;
3232
public String message;
33+
public String stackTrace;
3334
public long sequence;
3435

35-
public LogDTO(long sequence, String loggerName, LogLevel level, long unixtime, String message) {
36+
public LogDTO(long sequence, String loggerName, LogLevel level, long unixtime, String message, String stackTrace) {
3637
this.sequence = sequence;
3738
this.loggerName = loggerName;
3839
this.level = level;
3940
this.timestamp = new Date(unixtime);
4041
this.unixtime = unixtime;
4142
this.message = message;
43+
this.stackTrace = stackTrace;
4244
}
4345

4446
@Override

Diff for: bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/log/LogWebSocket.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
package org.openhab.core.io.websocket.log;
1414

1515
import java.io.IOException;
16+
import java.io.PrintWriter;
17+
import java.io.StringWriter;
1618
import java.util.ArrayList;
1719
import java.util.Collections;
1820
import java.util.Enumeration;
@@ -265,8 +267,18 @@ private static Predicate<Pattern> logPatternMatch(LogEntry logEntry) {
265267
}
266268

267269
private LogDTO map(LogEntry logEntry) {
270+
String stackTrace;
271+
if (logEntry.getException() != null) {
272+
StringWriter sw = new StringWriter();
273+
PrintWriter pw = new PrintWriter(sw);
274+
logEntry.getException().printStackTrace(pw);
275+
stackTrace = sw.toString();
276+
} else {
277+
stackTrace = "";
278+
}
279+
268280
return new LogDTO(logEntry.getSequence(), logEntry.getLoggerName(), logEntry.getLogLevel(), logEntry.getTime(),
269-
logEntry.getMessage());
281+
logEntry.getMessage(), stackTrace);
270282
}
271283

272284
private void stopDeferredScheduledFuture() {

0 commit comments

Comments
 (0)