Skip to content

Commit 67541de

Browse files
committed
exceptions log message instead of stacktraces
1 parent a42eb85 commit 67541de

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/SentryLogcatAdapter.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,11 @@ private static void addAsLog(
5757
if (!scopes.getOptions().getLogs().isEnabled()) {
5858
return;
5959
}
60-
if (tr == null) {
60+
final @Nullable String trMessage = tr != null ? tr.getMessage() : null;
61+
if (tr == null || trMessage == null) {
6162
scopes.logger().log(level, msg);
6263
} else {
63-
StringWriter sw = new StringWriter(256);
64-
PrintWriter pw = new PrintWriter(sw, false);
65-
tr.printStackTrace(pw);
66-
pw.flush();
67-
scopes.logger().log(level, msg != null ? (msg + "\n" + sw.toString()) : sw.toString());
68-
pw.close();
64+
scopes.logger().log(level, msg != null ? (msg + "\n" + trMessage) : trMessage);
6965
}
7066
}
7167

sentry-android-core/src/test/java/io/sentry/android/core/SentryLogcatAdapterTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class SentryLogcatAdapterTest {
113113
fixture.breadcrumbs.first().assert(tag, "$commonMsg error exception", SentryLevel.ERROR)
114114
fixture.logs
115115
.first()
116-
.assert("$commonMsg error exception\n${throwable.stackTraceToString()}", SentryLogLevel.ERROR)
116+
.assert("$commonMsg error exception\n${throwable.message}", SentryLogLevel.ERROR)
117117
}
118118

119119
@Test
@@ -124,7 +124,7 @@ class SentryLogcatAdapterTest {
124124
fixture.logs
125125
.first()
126126
.assert(
127-
"$commonMsg verbose exception\n${throwable.stackTraceToString()}",
127+
"$commonMsg verbose exception\n${throwable.message}",
128128
SentryLogLevel.TRACE,
129129
)
130130
}
@@ -136,7 +136,7 @@ class SentryLogcatAdapterTest {
136136
fixture.breadcrumbs.first().assert(tag, "$commonMsg info exception", SentryLevel.INFO)
137137
fixture.logs
138138
.first()
139-
.assert("$commonMsg info exception\n${throwable.stackTraceToString()}", SentryLogLevel.INFO)
139+
.assert("$commonMsg info exception\n${throwable.message}", SentryLogLevel.INFO)
140140
}
141141

142142
@Test
@@ -146,7 +146,7 @@ class SentryLogcatAdapterTest {
146146
fixture.breadcrumbs.first().assert(tag, "$commonMsg debug exception", SentryLevel.DEBUG)
147147
fixture.logs
148148
.first()
149-
.assert("$commonMsg debug exception\n${throwable.stackTraceToString()}", SentryLogLevel.DEBUG)
149+
.assert("$commonMsg debug exception\n${throwable.message}", SentryLogLevel.DEBUG)
150150
}
151151

152152
@Test
@@ -157,7 +157,7 @@ class SentryLogcatAdapterTest {
157157
fixture.logs
158158
.first()
159159
.assert(
160-
"$commonMsg warning exception\n${throwable.stackTraceToString()}",
160+
"$commonMsg warning exception\n${throwable.message}",
161161
SentryLogLevel.WARN,
162162
)
163163
}
@@ -169,7 +169,7 @@ class SentryLogcatAdapterTest {
169169
fixture.breadcrumbs.first().assert(tag, "$commonMsg wtf exception", SentryLevel.ERROR)
170170
fixture.logs
171171
.first()
172-
.assert("$commonMsg wtf exception\n${throwable.stackTraceToString()}", SentryLogLevel.FATAL)
172+
.assert("$commonMsg wtf exception\n${throwable.message}", SentryLogLevel.FATAL)
173173
}
174174

175175
@Test

0 commit comments

Comments
 (0)