Add stack trace to logger DTO (#4732)

Signed-off-by: Chris Jackson <chris@cd-jackson.com>
pull/4427/merge
Chris Jackson 2025-04-21 08:15:39 +12:00 committed by GitHub
parent 5c42be4861
commit f16f7cda31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -30,15 +30,17 @@ public class LogDTO implements Comparable<LogDTO> {
public Date timestamp;
public long unixtime;
public String message;
public String stackTrace;
public long sequence;
public LogDTO(long sequence, String loggerName, LogLevel level, long unixtime, String message) {
public LogDTO(long sequence, String loggerName, LogLevel level, long unixtime, String message, String stackTrace) {
this.sequence = sequence;
this.loggerName = loggerName;
this.level = level;
this.timestamp = new Date(unixtime);
this.unixtime = unixtime;
this.message = message;
this.stackTrace = stackTrace;
}
@Override

View File

@ -13,6 +13,8 @@
package org.openhab.core.io.websocket.log;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
@ -265,8 +267,18 @@ public class LogWebSocket implements LogListener {
}
private LogDTO map(LogEntry logEntry) {
String stackTrace;
if (logEntry.getException() != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
logEntry.getException().printStackTrace(pw);
stackTrace = sw.toString();
} else {
stackTrace = "";
}
return new LogDTO(logEntry.getSequence(), logEntry.getLoggerName(), logEntry.getLogLevel(), logEntry.getTime(),
logEntry.getMessage());
logEntry.getMessage(), stackTrace);
}
private void stopDeferredScheduledFuture() {