How to log without crash in Android? - android

I have integrated Fabric for crash capturing. But in a special case, I need to just log some details on the fabric. But I didn't find any way to add a log without a crash. Each time I need to crash app to see logs.
Crashlytics.log(subStr);
Crashlytics.logException(new RuntimeException("Exception"));
If I just add logs, I didn't see logs on Fabric. I need to explicitly throw an exception.
I am looking for a way where I can just log detail? I don't want crash logs.

Fabric crashlytics doesn't capture "non-exceptions".
Only when an exception is called will it appear in your console, whether that be fatal or non-fatal.
If you want to log events, any events you want, you can use Answers for that.
To use Answers, you will first have to implement it like this:
In your app level gradle:
implementation('com.crashlytics.sdk.android:answers:1.4.7#aar') {
transitive = true;
}
In your Manifest (I assume this will already be there since you're already using Crashlytics):
<meta-data
android:name="io.fabric.ApiKey"
android:value="3323d86155070b69e4558c773e7bdb6dc495cd9f"
/>
Then in your MainActivity or your Application class, you should initialize Answers, like this:
Fabric.with(this, new Answers());
Whenever you want to log something you can call it like this example:
Answers.getInstance().logCustom(new CustomEvent("Video Played")
.putCustomAttribute("Category", "Comedy")
.putCustomAttribute("Length", 350));
The log will then be displayed in your Fabrics console.
It's also important to note that you will soon have to move to Google Crashlytics, as Fabric is closing.

Crashlytics.getInstance().core.logException(new RuntimeException("Exception"));
Try this. I got Log in Fabric without crash

Related

Crashlytics not showing the logs

In my android project I'm using Crashlytics to get the app crash reports.I have also added the logs to see it in my dashboard.For adding logs I've used
Crashlytics.log (Log.ERROR, TAG, message);
So when I run the app for testing,and open the activity where I've added the Crashlytics log statements ,the logs were generated for the first time .I can see them on the dashboard. But when I again open the same activity ,I'm not able to see the new logs generated . I read here that if the logs are not seen on the dashboard then restart the app.I did that ,but still couldn't see the logs on the dashboard,my dashboard only shows the logs which were generated for the first time.I also tried testing my app on different device but it still doesn't show on the dashboard.Can somebody please help me in solving this issue .Why am I not able to see all non-fatal logs on my dashboard?
IF this doesn't produce errors you have to wait for logs registered on your dashboard in free account
Mike from Firebase here.
Crashlytics.log (Log.ERROR, TAG, message); will only be displayed if there is also a non-fatal - Crashlytics.logException(e); or fatal exception. We prioritize capturing exceptions (fatal or non-fatal) over logs so if you log the value immediately before the exception, depending on the size of the log, it may not be recorded. This is because we think capturing the exception is more important than the log.

Unable to see Dashboard of fabric

I have installed the fabric,integrated jar files and API key.I am always on "https://www.fabric.io/onboard" instead of " https://fabric.io/dashboard".Unable to see the crash report.I have used correct email Id.
Please help,Thanks in advance.
you can see the app here
https://fabric.io/home
and please wait some time to get updated .also double check in your app below line is enabled or not
Fabric.with(this, new Crashlytics());
also check these from the documentation
If you're getting started with Crashlytics for Android,
Make sure our SDK line is after all other 3rd-party SDKs Force a crash
and then relaunch the app. If you're using our
Crashlytics.getInstance().crash() method for testing purposes, make
sure it's not in the onCreate method of your launch Activity

How to send Crashlytics log

I am using Crashlytics (now known as Fabric) in my app.
It works well when the app crashes. I can find the issue on the dashboard.
I am trying to use the logging. Something like:
Crashlytics.log(Log.WARN,MYTAG,"Error message");
I am not able to send this log in the dashboard. I have just tried to add something like:
Crashlytics.logException(new RuntimeException("Fake exception"));
but it doesn't send the log.
Can Crashlytics send the log?
You are sending the Log properly. But see what Official doc says Logging Caught Exceptions
All logged exceptions will appear as "non-fatal" issues in the Crashlytics dashboard.
To reduce your users' network traffic, Crashlytics batches logged exceptions together and sends them the next time the app launches. If you don't see logged exceptions in your Crashlytics web dashboard, try restarting your app!
In Android, send a custom crash by using
Crashlytics.logException(new RuntimeException("Fake exception"));
Then restart your application
In Crashlytics, select the Non-Fatals
On newer versions of Crashlytics, you need to use these functions:
FirebaseCrashlytics.getInstance().log("Your message goes here")
FirebaseCrashlytics.getInstance().recordException(RuntimeException("Your message goes here"))
Edit:
As #Peter mentioned in the comments, using log alone will not work and you have to use recordException function to bundle your log message along with the exception

Cannot see Crittercism app crashes on Android

I use crittercism for my app. Here is what i do to initialize Crittercism:
I only use the following permission:
<uses-permission android:name="android.permission.INTERNET"/>
and i initialize Crittercism like the following:
Crittercism.initialize(getApplicationContext(), "MY_APP_ID");
I do nothing else.
I can see some information about app installs etc, but i cannot see crash reports. I do the following when i click a button in my app and deliberately crash the app:
public void onClick(){
Integer i = null;
i++;
}
But i cannot see the crash report of this situation. Can anyone tell me why? Do i need to add mappings.txt file etc.?
Thanks
As the official Crittercism documentation says, you need more permissions.
Add the following permissions to your app’s AndroidManifest.xml file.
INTERNET
Required. Used to report data to Crittercism.
ACCESS_NETWORK_STATE
Optional. Allows providing network connectivity information such as carrier and network type.
READ_LOGS
Optional. Allows collecting logcat data to be attached to crashes and handled exceptions.
GET_TASKS
Optional. Allows augmenting crash reports with information on the activity running during a crash.
Documentation
You probably need "GET_TASKS" in order to have crash reports.
I found the problem.
It seems that in the developer console, the platform was set to IOS, i changed it to Android and i can see crash reports now.

Trouble with logging my data with crashlytics

I'm trying to get logs with some service data with Crashlytics in my android application. But I don't see my logs in dashboard.
I used this:
String myLog = getServiceData(); //myLog is not null and non-empty
CrashLytics.log(myLog);
and this:
String myLog = getServiceData(); //myLog is not null and non-empty
CrashLytics.log(Log.Error, getString(R.string.app_name), myLog);
I tried to generate exception in my application and handle it, but have no results:
try {
int a = 0;
a = 1/a;
}
catch (Exception e) {
CrashLytics.log(myLog);
}
Also I read on Crashlytics log not sent I need to initialize crashlytics before log data. I put Crashlytics.start(this) in onStart() event of my Activity but didn't see my logs in dashboard again. At last I tried to put Crashlitycs.start(this) directly before logging my data, but still have no logs in dashboard.
Plase, tell me what I do wrong and how to get my custom logs in Crashlytics dashboard?
I had a similar situation. With some experimenting, I was able to deduce the rules to Crashlytics' behavior.
I'm sharing my learnings here so (hopefully) others don't have to go through the arduous and time-consuming process that I did to figure it out.
Crashlytics will only upload a crash report "to the dashboard" immediately if a fatal exception occurs. In other words, when your app crashes. And nothing shows in the dashboard unless and until a crash report is uploaded.
If you log a non-fatal exception, using CrashLytics.logException(e), a crash report will not be uploaded till the next time your app is restarted. So you will not see the exception in the Crashlytics dashboard till an app restart.
You can tell when an upload occurs because you'll see this sort of message in LogCat:
07-17 19:30:41.477 18815-18906/com.foo.bar I/Crashlytics﹕ Crashlytics report upload complete: 55A9BA0C01D7-0001-462D-B8B4C49333333.cls
A Crashlytics log message must be associated with a fatal or non-fatal exception to show up in the dashboard.
Furthermore, log messages that aren't associated with an exception do not survive app restart.
So, if you do something like log a few messages, then restart the app, then the app throws an exception, or it logs a non-fatal exception using Crashlytics.logException(), the log messages will be lost. They will not show up in the dashboard.
If you want to log some messages without a fatal exception, use one or more Crashlytics.log() statements followed by Crashlytics.logException().
To verify that it works, have the code run, then restart the app. In the dashboard, you should see the logs associated with the issue created for the non-fatal exception. In the wild, you'll just have to trust your users restart the app with some regularity.
On the Fabric/Crashlytics dashboard, you'll need to select All Events or (if you want to see just your logging calls) Non-Fatals.
according to Crashlytics knowledgebase:
Logged messages are associated with your crash data and are visible in
the Crashlytics dashboard if you look at the specific crash itself.
And from my experience this seems true. However I am unsure as to what determines which logging is associated with a crash report. Perhaps a time window (time around crash) or a limited number of logs (before the crash) is associated with the crash report?
However Crashlytics knowledgebase does say that exceptions can be logged:
All logged exceptions will appear as "non-fatal" issues in the
Crashlytics dashboard.
So if you changed your try/catch to:
try {
int a = 0;
a = 1/a;
}
catch (Exception e) {
CrashLytics.logException(e);
}
then it should show up in the Crashlytics dashboard.
This is an old question but since I was having the same problem today, I figured I should post my solution (it's in Kotlin though).
With Crashlytics now a part of Google's Firebase offering, it initializes behind the scenes, so a solution I wrote a few years ago had to be updated to this:
Implement some kind of log caching, First In First Out. I put one together based on cache-lite.
Put this function in YourApplicationClass that extends Application:
fun setExceptionHandler() {
val defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, ex ->
Crashlytics.log(cacheLoggingTree.getAll().joinToString("++"))
Crashlytics.logException(ex)
defaultExceptionHandler.uncaughtException(thread, ex)
}
}
Then you call the function from the end of your onCreate function in your MainActivity:
(application as YourApplicationClass).setExceptionHandler()
With that, any exceptions that get thrown will first post the most recent log entries, then log the exception. You probably want to be cautious with how many lines you cache though, lest you overload the system.
Also, I used ++ as a flag to manually replace with carriage returns when you download the log, since the \n I had gets stripped in the upload process.
Instead of catching the exception and logging it, you can instead use RuntimeExceptions:
throw new RuntimeException("Test crash");
Android Studio will not require you to catch these, thus having the app terminate and upload the report immediately.

Categories

Resources