Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Log stacktraces in SystemOutLogger #498

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions sentry-core/src/main/java/io/sentry/core/SystemOutLogger.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.sentry.core;

import java.io.PrintWriter;
import java.io.StringWriter;
import org.jetbrains.annotations.NotNull;

/** ILogger implementation to System.out. */
public final class SystemOutLogger implements ILogger {

Expand Down Expand Up @@ -27,7 +31,9 @@ public void log(SentryLevel level, String message, Object... args) {
@Override
public void log(SentryLevel level, String message, Throwable throwable) {
System.out.println(
String.format("%s: %s", level, String.format(message, throwable.toString())));
String.format(
"%s: %s\n%s",
level, String.format(message, throwable.toString()), captureStackTrace(throwable)));
}

/**
Expand All @@ -42,6 +48,18 @@ public void log(SentryLevel level, String message, Throwable throwable) {
@Override
public void log(SentryLevel level, Throwable throwable, String message, Object... args) {
System.out.println(
String.format("%s: %s \n %s", level, String.format(message, args), throwable.toString()));
String.format(
maciejwalkowiak marked this conversation as resolved.
Show resolved Hide resolved
"%s: %s \n %s\n%s",
level,
String.format(message, args),
throwable.toString(),
captureStackTrace(throwable)));
}

private String captureStackTrace(@NotNull Throwable throwable) {
maciejwalkowiak marked this conversation as resolved.
Show resolved Hide resolved
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
throwable.printStackTrace(printWriter);
return stringWriter.toString();
}
}