diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/resources/logback-spring.xml b/apps/levende-arbeidsforhold-ansettelse/src/main/resources/logback-spring.xml
index 72ecf8f1337..4f7136b7def 100644
--- a/apps/levende-arbeidsforhold-ansettelse/src/main/resources/logback-spring.xml
+++ b/apps/levende-arbeidsforhold-ansettelse/src/main/resources/logback-spring.xml
@@ -5,18 +5,7 @@
-1
true
-
-
-
-
-
-
-
-
-
-
-
-
+ no.nav.testnav
diff --git a/libs/reactive-core/src/main/java/no/nav/testnav/libs/reactivecore/logging/TestnavLogbackEncoder.java b/libs/reactive-core/src/main/java/no/nav/testnav/libs/reactivecore/logging/TestnavLogbackEncoder.java
index bdcfb6cacd2..67acbbe5fee 100644
--- a/libs/reactive-core/src/main/java/no/nav/testnav/libs/reactivecore/logging/TestnavLogbackEncoder.java
+++ b/libs/reactive-core/src/main/java/no/nav/testnav/libs/reactivecore/logging/TestnavLogbackEncoder.java
@@ -1,27 +1,35 @@
package no.nav.testnav.libs.reactivecore.logging;
import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.ThrowableProxy;
import com.fasterxml.jackson.core.JsonFactory;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.logstash.logback.encoder.LogstashEncoder;
+import org.springframework.util.StringUtils;
import java.io.ByteArrayOutputStream;
-import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.regex.Pattern;
+import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
+import static org.springframework.util.StringUtils.truncate;
/**
* Config:
- * {@code maxStackTraceLength}: Default 480, set to a negative number to disable truncation of stack trace altogether.
- * @{code addCauses}: If {@code true}, adds the cause(s) to the stack trace (without stack traces for each cause) Truncated according to above.
+ *
+ * - {@code maxStackTraceLength}: Default 480, set to <1 to disable truncation of stack trace altogether.
+ * - {@code addCauses}: If enabled, adds the cause(s) to the stack trace (with stack traces for each cause) Truncated according to above, filtered according to below.
+ * - {@code stackTraceIncludePrefix}: If set, only include stack trace elements that starts with the given prefix, e.g. "no.nav.testnav".
+ *
+ * Copy of {@code no.nav.testnav.libs.servletcore.logging.TestnavLogbackEncoder}.
+ *
+ * @see StringUtils#truncate(CharSequence, int)
*/
@Slf4j
+@SuppressWarnings("java:S110")
public class TestnavLogbackEncoder extends LogstashEncoder {
// matches exactly 11 digits (\\d{11}) that are not immediately preceded ((? 0 ?
+ truncate(writer.toString(), maxStackTraceLength) :
+ writer.toString();
+ }
+ }
+ return null;
+ }
+
+ private void appendStackTraceElements(StackTraceElement[] elements, StringWriter writer) {
+ for (StackTraceElement element : elements) {
+ if (isNull(stackTraceIncludePrefix) || stackTraceIncludePrefix.isEmpty() || element.toString().startsWith(stackTraceIncludePrefix)) {
+ writer
+ .append("\tat ")
+ .append(element.toString())
+ .append("\n");
+ }
+ }
+ }
+
+ private void appendStackTraceCauses(ThrowableProxy exception, StringWriter writer) {
+ if (addCauses) {
+ var cause = exception;
+ while (!isNull(cause.getCause())) {
+ cause = (ThrowableProxy) cause.getCause();
+ writer
+ .append("caused by ")
+ .append(cause.getClassName())
+ .append(": ")
+ .append(cause.getMessage())
+ .append("\n");
+ if (!isNull(cause.getThrowable())) {
+ appendStackTraceElements(cause.getThrowable().getStackTrace(), writer);
+ }
+ }
}
}