Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 10 additions & 8 deletions sentry-android/src/main/java/com/joshdholtz/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;
import java.util.regex.Pattern;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
Expand Down Expand Up @@ -98,10 +98,8 @@ public class Sentry {
private Map<String, Object> contexts = Collections.emptyMap();

private static final String TAG = "Sentry";
private static final String DEFAULT_BASE_URL = "https://app.getsentry.com";

private Sentry() {

}

private static void log(String text) {
Expand Down Expand Up @@ -234,14 +232,18 @@ public static void captureMessage(String message, SentryEventLevel level) {
}

public static void captureException(Throwable t) {
Sentry.captureException(t, SentryEventLevel.ERROR);
Sentry.captureException(t, t.getMessage(), SentryEventLevel.ERROR);
}

public static void captureException(Throwable t, String message) {
Sentry.captureException(t, message, SentryEventLevel.ERROR);
}

public static void captureException(Throwable t, SentryEventLevel level) {
public static void captureException(Throwable t, String message, SentryEventLevel level) {
String culprit = getCause(t, t.getMessage());

Sentry.captureEvent(new SentryEventBuilder()
.setMessage(t.getMessage())
.setMessage(message)
.setCulprit(culprit)
.setLevel(level)
.setException(t)
Expand Down Expand Up @@ -689,7 +691,7 @@ public static class SentryEventBuilder implements Serializable {
// dalvik.system.*
static final String isInternalPackage = "^(java|android|com\\.android|com\\.google\\.android|dalvik\\.system)\\..*";

private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~ this fixes a warning in AndroidStudio

static {
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
}
Expand All @@ -700,7 +702,7 @@ public JSONObject toJSON() {
return new JSONObject(event);
}

public static enum SentryEventLevel {
public enum SentryEventLevel {

FATAL("fatal"),
ERROR("error"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public void onClickBreak(View view) {
s.length();
}

public void onClickCapture(View view) {
try {
onClickBreak(view);
} catch (Exception e) {
Sentry.captureException(e, "Exception caught in click handler");
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
Expand Down
10 changes: 8 additions & 2 deletions sentry-app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
Expand All @@ -10,4 +11,9 @@
android:layout_height="wrap_content"
android:onClick="onClickBreak" />

</RelativeLayout>
<Button android:text="Click to capture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClickCapture" />

</LinearLayout>