Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timber.e with an exception logs to Crashlytics #1102

Merged
merged 1 commit into from
Mar 16, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import androidx.annotation.NonNull;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore;
import com.quran.labs.androidquran.component.activity.PagerActivityComponent;
import com.quran.labs.androidquran.component.application.DaggerApplicationComponent;
import com.quran.labs.androidquran.component.application.ApplicationComponent;
import com.quran.labs.androidquran.component.application.DaggerApplicationComponent;
import com.quran.labs.androidquran.module.application.ApplicationModule;
import com.quran.labs.androidquran.util.QuranSettings;
import com.quran.labs.androidquran.util.RecordingLogTree;

import java.util.Locale;

import androidx.annotation.NonNull;
import io.fabric.sdk.android.Fabric;
import timber.log.Timber;

public class QuranApplication extends Application {
private ApplicationComponent applicationComponent;
private PagerActivityComponent pagerActivityComponent;

@Override
public void onCreate() {
Expand Down Expand Up @@ -77,8 +75,4 @@ private void updateLocale(@NonNull Context context, @NonNull Locale locale) {
}
resources.updateConfiguration(config, resources.getDisplayMetrics());
}

public PagerActivityComponent getPagerActivityComponent() {
return pagerActivityComponent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import android.util.Log;

import com.crashlytics.android.Crashlytics;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayDeque;
import java.util.Deque;

import timber.log.Timber;

/**
* A logging implementation which buffers the last 200 messages.
* It uploads them to Crashlytics upon the logging of an error.
*
* Slightly modified version of Telecine's BugsnagTree.
* https://github.com/JakeWharton/Telecine
*/
Expand All @@ -20,14 +26,19 @@ public class RecordingLogTree extends Timber.Tree {
private final Deque<String> buffer = new ArrayDeque<>(BUFFER_SIZE + 1);

@Override
protected void log(int priority, String tag, String message, Throwable t) {
protected void log(int priority, String tag, @NotNull String message, Throwable t) {
message = System.currentTimeMillis() + " " + priorityToString(priority) + " " + message;
synchronized (buffer) {
buffer.addLast(message);
if (buffer.size() > BUFFER_SIZE) {
buffer.removeFirst();
}
}

if (t != null && priority == Log.ERROR) {
Crashlytics.log(getLogs());
Crashlytics.logException(t);
}
}


Expand Down