How to programmatically get android logs from a release build - android

I've seen plenty of ways of getting system logs in Android with logcat and the like, but not so much about app logs (except for the usual USB + adb solution).
My B2B Android app produces useful logging created with Log.i calls. Whilst in Studio these are very useful for debugging, it would also be useful to get these from customer's installs when things go wrong, i.e. from a release build out in the wild. Customers are generally not techies so getting logs via adb isn't really an option.
Is there a way within the app code itself to grab all the log contents?
Perhaps the SDK provides a way to do this?
I could then send that to my server or by email. I'm thinking it'll be useful for my customers to just hit a button so I can get an instantaneous snapshot of what is happening in the app.
Thanks in advance
UPDATE
There doesn't seem to be a way to do this, aside from writing to a file and sending that file. Which I guess is a good a solution as any.
Two other interesting ones that have come up are:
Firebase (from Mohammed's comment) - can log events:https://firebase.google.com/docs/analytics/android/events
Instabug

we can write write logs to file using java.util.logging.Logger API.
How to write logs in text file when using java.util.logging.Logger
Check out here for writting crash log to a file

Related

Whats the best way to create a debugging history log for an Android application

So I have an android application that has a myriad of activities (intents?) which all do their own thing. We were wanting to create a sort of debug log though, one where you can see what the user has been through and error that occurs. You may have had to send one before if you've run into a bug with a program you've used.
My initial thoughts are to just create a class where I can send information/data to and it just writes it onto a text file. It would need to be accessible across all the activities so that I can easily write to it and re-use it.
I do wonder whether that's a good way to go through, noted that it doesn't really save any actual errors but only data I tell it to. And I'm not sure if its a great idea to be constantly opening->writing->closing a file for a debug log.
Is there a smarter way? Or a common pattern that would be good to use?
Thanks so much!
Sentry's Android SDK, will automatically report errors and exceptions in your application.
The Sentry SDK catches the exception right before the crash and builds a crash report that will persist to the disk. The SDK will try to send the report right after the crash, but since the environment may be unstable at the crash time, the report is guaranteed to send once the application is started again.
You can see full documentation here

How to find the reason my app stopped without Android Studio

I just finished my last app and after intensive testing on android studio no bugs or errors pooped up.
But when I use my phone for some time and try to check my app it crashes, and error pops up.
Is there a way to find out the stack trace od that error? specially since its not connected to my PC.
You can integrate tools for analyse, like:
Crashlytics
So you have a dashboard and can setting a e-mail for warning.
You can use different options:
Store logcat file in Internal memory as txt file. This will be best solution since it will provide all the necessary information of pre-conditons for the crash
Implement crashanalytics like Hockeyapp
Use remote debugging. Refer this official document for more info
You can find more details for approach 1 & 2 at: remote logcat - Android Studio

Android crash logs default location

Is there any way that I can get crash logs from a device which is signed with a public key, but not uploaded in android market? I need a way to get crash logs from a specific device to see why my application is crashing on it. Anyway to do this?
There are various frameworks for this. ACRA is one of them (http://code.google.com/p/acra/). Another that I frequently use is Bugsense (http://bugsense.com/). There are more also, but I think these two will be perfect for you!
Hope this helps!
Update:
In case you don't want to add any external library, you have to do it by your own. This means that Android in general has a mechanism to catch all uncaught exceptions. This is http://developer.android.com/reference/java/lang/Thread.html#setDefaultUncaughtExceptionHandler%28java.lang.Thread.UncaughtExceptionHandler%29.
There you can catch all uncaught exceptions and handle them as you wish (write to a file, send them, etc). All there libraries internally use this mechanism, but provide a wrapper to the user.
One option is installing and running a LogCat application (e.g. aLogcat) on the target phone. This can capture all logcat output - including exceptions - for the overall system and/or the app in question - using a filter.

The application has stopped unexpectedly: How to Debug?

Please note, unlike many other questions having the subject title "application has stopped unexpectedly", I am not asking for troubleshooting a particular problem.
Rather, I am asking for an outline of the best strategy for an Android/Eclipse/Java rookie to tackle this formidable task of digesting huge amounts of information in order to develop (and debug!) a simple Android application.
In my case, I took the sample skeleton app from the SDK, modified it slightly and what did I get the moment I try to run it?
The application
(process.com.example.android.skeletonapp)
has stopped unexpectedly. Please try
again.
OK, so I know that I have to look LogCat. It's full of timestamped lines staring at me... What do I do now? What do I need to look for?
Is there a way to single-step the program, to find the statement that makes the app crash? (I thought Java programs never crash, but apparently I was mistaken)
How do I place a breakpoint?
Can you recommend an Android debug tutorial online, other than this one?
I'm an Eclipse/Android beginner as well, but hopefully my simple debugging process can help...
You set breakpoints in Eclipse by right-clicking next to the line you want to break at and selecting "Toggle Breakpoint". From there you'll want to select "Debug" rather than the standard "Run", which will allow you to step through and so on. Use the filters provided by LogCat (referenced in your tutorial) so you can target the messages you want rather than wading through all the output. That will (hopefully) go a long way in helping you make sense of your errors.
As for other good tutorials, I was searching around for a few myself, but didn't manage to find any gems yet.
Filter your log to just Error and look for FATAL EXCEPTION
If you use the Logcat display inside the 'debug' perspective in Eclipse the lines are colour-coded. It's pretty easy to find what made your app crash because it's usually in red.
The Java (or Dalvik) virtual machine should never crash, but if your program throws an exception and does not catch it the VM will terminate your program, which is the 'crash' you are seeing.
Check whether your app has the needed permissions.I was also getting the same error and I checked the logcat debug log which showed this:
04-15 13:38:25.387: E/AndroidRuntime(694): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:555-555-5555 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{44068640 694:rahulserver.test/10055} (pid=694, uid=10055) requires android.permission.CALL_PHONE
I then gave the needed permission in my android-manifest which worked for me.
From the Home screen, press the Menu key.
List item
Touch Settings.
Touch Applications.
Touch Manage Applications.
Touch All.
Select the application that is having issues.
Touch Clear data and Clear cache if they are available. This resets the app as if it was new, and may delete personal data stored in the app.

Android read error log from handset

How can I read the error log applications make? Is there any software which reads the error log from the handset and displays it?
I don't want to debug the app using eclipse, I'm looking for a handset based error log viewer.
There are a number of free applications in the Android Market which will collect the device log.
One which looks promising is Log Collector, not least because it is open source. You can find it on Google Code here and on androlib.com here.
Here's another Log Collecting app produced by the creators of Locale.
I quite like the one I wrote ;-)
It's called SendLog
http://l6n.org/android/sendlog.shtml
Alogcat seems OK. It's a bit verbose, though.

Categories

Resources