|
2 | 2 |
|
3 | 3 | import android.util.Log;
|
4 | 4 | import io.sentry.Breadcrumb;
|
| 5 | +import io.sentry.ScopesAdapter; |
5 | 6 | import io.sentry.Sentry;
|
6 | 7 | import io.sentry.SentryLevel;
|
| 8 | +import io.sentry.SentryLogLevel; |
| 9 | +import java.io.PrintWriter; |
| 10 | +import java.io.StringWriter; |
7 | 11 | import org.jetbrains.annotations.ApiStatus;
|
8 | 12 | import org.jetbrains.annotations.NotNull;
|
9 | 13 | import org.jetbrains.annotations.Nullable;
|
@@ -44,73 +48,104 @@ private static void addAsBreadcrumb(
|
44 | 48 | Sentry.addBreadcrumb(breadcrumb);
|
45 | 49 | }
|
46 | 50 |
|
| 51 | + private static void addAsLog( |
| 52 | + @NotNull final SentryLogLevel level, |
| 53 | + @Nullable final String msg, |
| 54 | + @Nullable final Throwable tr) { |
| 55 | + final @NotNull ScopesAdapter scopes = ScopesAdapter.getInstance(); |
| 56 | + if (tr == null) { |
| 57 | + scopes.logger().log(level, msg); |
| 58 | + } else { |
| 59 | + StringWriter sw = new StringWriter(256); |
| 60 | + PrintWriter pw = new PrintWriter(sw, false); |
| 61 | + tr.printStackTrace(pw); |
| 62 | + pw.flush(); |
| 63 | + scopes.logger().log(level, msg != null ? (msg + "\n" + sw.toString()) : sw.toString()); |
| 64 | + pw.close(); |
| 65 | + } |
| 66 | + } |
| 67 | + |
47 | 68 | public static int v(@Nullable String tag, @Nullable String msg) {
|
48 | 69 | addAsBreadcrumb(tag, SentryLevel.DEBUG, msg);
|
| 70 | + addAsLog(SentryLogLevel.TRACE, msg, null); |
49 | 71 | return Log.v(tag, msg);
|
50 | 72 | }
|
51 | 73 |
|
52 | 74 | public static int v(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
|
53 | 75 | addAsBreadcrumb(tag, SentryLevel.DEBUG, msg, tr);
|
| 76 | + addAsLog(SentryLogLevel.TRACE, msg, tr); |
54 | 77 | return Log.v(tag, msg, tr);
|
55 | 78 | }
|
56 | 79 |
|
57 | 80 | public static int d(@Nullable String tag, @Nullable String msg) {
|
58 | 81 | addAsBreadcrumb(tag, SentryLevel.DEBUG, msg);
|
| 82 | + addAsLog(SentryLogLevel.DEBUG, msg, null); |
59 | 83 | return Log.d(tag, msg);
|
60 | 84 | }
|
61 | 85 |
|
62 | 86 | public static int d(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
|
63 | 87 | addAsBreadcrumb(tag, SentryLevel.DEBUG, msg, tr);
|
| 88 | + addAsLog(SentryLogLevel.DEBUG, msg, tr); |
64 | 89 | return Log.d(tag, msg, tr);
|
65 | 90 | }
|
66 | 91 |
|
67 | 92 | public static int i(@Nullable String tag, @Nullable String msg) {
|
68 | 93 | addAsBreadcrumb(tag, SentryLevel.INFO, msg);
|
| 94 | + addAsLog(SentryLogLevel.INFO, msg, null); |
69 | 95 | return Log.i(tag, msg);
|
70 | 96 | }
|
71 | 97 |
|
72 | 98 | public static int i(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
|
73 | 99 | addAsBreadcrumb(tag, SentryLevel.INFO, msg, tr);
|
| 100 | + addAsLog(SentryLogLevel.INFO, msg, tr); |
74 | 101 | return Log.i(tag, msg, tr);
|
75 | 102 | }
|
76 | 103 |
|
77 | 104 | public static int w(@Nullable String tag, @Nullable String msg) {
|
78 | 105 | addAsBreadcrumb(tag, SentryLevel.WARNING, msg);
|
| 106 | + addAsLog(SentryLogLevel.WARN, msg, null); |
79 | 107 | return Log.w(tag, msg);
|
80 | 108 | }
|
81 | 109 |
|
82 | 110 | public static int w(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
|
83 | 111 | addAsBreadcrumb(tag, SentryLevel.WARNING, msg, tr);
|
| 112 | + addAsLog(SentryLogLevel.WARN, msg, tr); |
84 | 113 | return Log.w(tag, msg, tr);
|
85 | 114 | }
|
86 | 115 |
|
87 | 116 | public static int w(@Nullable String tag, @Nullable Throwable tr) {
|
88 | 117 | addAsBreadcrumb(tag, SentryLevel.WARNING, tr);
|
| 118 | + addAsLog(SentryLogLevel.WARN, null, tr); |
89 | 119 | return Log.w(tag, tr);
|
90 | 120 | }
|
91 | 121 |
|
92 | 122 | public static int e(@Nullable String tag, @Nullable String msg) {
|
93 | 123 | addAsBreadcrumb(tag, SentryLevel.ERROR, msg);
|
| 124 | + addAsLog(SentryLogLevel.ERROR, msg, null); |
94 | 125 | return Log.e(tag, msg);
|
95 | 126 | }
|
96 | 127 |
|
97 | 128 | public static int e(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
|
98 | 129 | addAsBreadcrumb(tag, SentryLevel.ERROR, msg, tr);
|
| 130 | + addAsLog(SentryLogLevel.ERROR, msg, tr); |
99 | 131 | return Log.e(tag, msg, tr);
|
100 | 132 | }
|
101 | 133 |
|
102 | 134 | public static int wtf(@Nullable String tag, @Nullable String msg) {
|
103 | 135 | addAsBreadcrumb(tag, SentryLevel.ERROR, msg);
|
| 136 | + addAsLog(SentryLogLevel.FATAL, msg, null); |
104 | 137 | return Log.wtf(tag, msg);
|
105 | 138 | }
|
106 | 139 |
|
107 | 140 | public static int wtf(@Nullable String tag, @Nullable Throwable tr) {
|
108 | 141 | addAsBreadcrumb(tag, SentryLevel.ERROR, tr);
|
| 142 | + addAsLog(SentryLogLevel.FATAL, null, tr); |
109 | 143 | return Log.wtf(tag, tr);
|
110 | 144 | }
|
111 | 145 |
|
112 | 146 | public static int wtf(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
|
113 | 147 | addAsBreadcrumb(tag, SentryLevel.ERROR, msg, tr);
|
| 148 | + addAsLog(SentryLogLevel.FATAL, msg, tr); |
114 | 149 | return Log.wtf(tag, msg, tr);
|
115 | 150 | }
|
116 | 151 | }
|
0 commit comments