-
Notifications
You must be signed in to change notification settings - Fork 1
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
[ADDED] Crashlytics tree for release builds #108
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot wasn't able to review any files in this pull request.
Files not reviewed (2)
- app/src/main/java/dev/hossain/weatheralert/WeatherAlertApp.kt: Language not supported
- app/src/main/java/dev/hossain/weatheralert/util/CrashlyticsTree.kt: Language not supported
ChatGPT Yes, you can plant a custom Here’s how you can implement a custom Step 1: Create a Custom
|
Gemini Yes, you can create a custom 1. Set up Crashlytics:
2. Create a custom Timber Tree: import android.util.Log;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import timber.log.Timber;
public class CrashlyticsTree extends Timber.Tree {
private final FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
@Override
protected void log(int priority, String tag, String message, Throwable t) {
if (priority == Log.VERBOSE || priority == Log.DEBUG || priority == Log.INFO) {
return; // Don't log VERBOSE, DEBUG, INFO in Crashlytics
}
if (t != null) {
crashlytics.recordException(t);
} else {
crashlytics.log(message);
}
}
} 3. Plant the tree in your Application class: import android.app.Application;
import timber.log.Timber;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
if (!BuildConfig.DEBUG) { // Only plant the CrashlyticsTree in production
Timber.plant(new CrashlyticsTree());
} else {
Timber.plant(new Timber.DebugTree()); // Use DebugTree for development
}
}
} Explanation:
Important considerations:
By following these steps, you can effectively use Timber to send error logs to Crashlytics in your production Android app, improving your ability to track and fix crashes. |
This pull request introduces a new custom logging mechanism to the
WeatherAlertApp
by integrating Crashlytics for production builds and refactoring the existing logging setup. The key changes include the addition of a customCrashlyticsTree
class and the refactoring of the logging tree installation process.Logging Mechanism Enhancement:
app/src/main/java/dev/hossain/weatheralert/WeatherAlertApp.kt
: Refactored the logging setup by moving the logging tree installation logic to a newinstallLoggingTree
method. This method now plants aTimber.DebugTree
for debug builds and a customCrashlyticsTree
for production builds.app/src/main/java/dev/hossain/weatheralert/util/CrashlyticsTree.kt
: Added a newCrashlyticsTree
class that extendsTimber.Tree
to log messages with a severity of WARN or higher to Firebase Crashlytics. This class handles both logging messages and recording exceptions.app/src/main/java/dev/hossain/weatheralert/WeatherAlertApp.kt
: Updated imports to include the newly createdCrashlyticsTree
class.