Skip to content

Commit

Permalink
Fiks etter kommentar
Browse files Browse the repository at this point in the history
  • Loading branch information
stigus committed May 2, 2024
1 parent 44a18fc commit 80b7ddc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.io.StringWriter;
import java.util.regex.Pattern;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;

@Slf4j
public class TestnavLogbackEncoder extends LogstashEncoder {
Expand All @@ -36,15 +36,15 @@ public byte[] encode(ILoggingEvent event) {
generator.writeStringField("thread_name", event.getThreadName());
generator.writeStringField("level", event.getLevel().toString());

if (!isNull(event.getThrowableProxy())) {
if (nonNull(event.getThrowableProxy())) {
var exception = (ThrowableProxy) event.getThrowableProxy();
if (!isNull(exception.getThrowable())) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
if (nonNull(exception.getThrowable())) {
var sw = new StringWriter();
var pw = new PrintWriter(sw);
for (StackTraceElement element : exception.getThrowable().getStackTrace()) {
pw.println("\tat " + element);
}
String stackTrace = sw.toString().substring(0, 480); //Limit the stack trace to 480 characters
var stackTrace = sw.toString().substring(0, 480); //Limit the stack trace to 480 characters
generator.writeStringField("stack_trace", stackTrace);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.io.StringWriter;
import java.util.regex.Pattern;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;

@Slf4j
public class TestnavLogbackEncoder extends LogstashEncoder {
Expand All @@ -36,15 +36,15 @@ public byte[] encode(ILoggingEvent event) {
generator.writeStringField("thread_name", event.getThreadName());
generator.writeStringField("level", event.getLevel().toString());

if (!isNull(event.getThrowableProxy())) {
if (nonNull(event.getThrowableProxy())) {
var exception = (ThrowableProxy) event.getThrowableProxy();
if (!isNull(exception.getThrowable())) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
if (nonNull(exception.getThrowable())) {
var sw = new StringWriter();
var pw = new PrintWriter(sw);
for (StackTraceElement element : exception.getThrowable().getStackTrace()) {
pw.println("\tat " + element);
}
String stackTrace = sw.toString().substring(0, 480); //Limit the stack trace to 480 characters
var stackTrace = sw.toString().substring(0, 480); //Limit the stack trace to 480 characters
generator.writeStringField("stack_trace", stackTrace);
}
}
Expand Down

0 comments on commit 80b7ddc

Please sign in to comment.