I am new to Android. Please help me to know about the best practice of using Android Logger. Do I need to keep a file somewhere in android and keep on writing logs into it, or writing of logs into file is not necessary. What could be the best practice.
My real intention is this.
Once we go live, if our customers come back and tell us that something crashed or does not work in their android , then how do we debug ?
In the web application, I would ask my server administrator to provide the log files. What do we do with the android application when there is no server error, but something failed in the phone. Is there a way to get logs from the phone.
Thanks
Ravi
Depends on what you need, you need logging for semi debugging your application than you can easily use the buildin Log functionality. Via Logcat you can easiliy see the logs.
http://www.vogella.com/tutorials/AndroidLogging/article.html
//Declare a tag
String TAG= "SomeActivity";
//Log
Log.d(TAG, "Hello World"); //debug
Log.e(TAG, "Hello World"); //error
If you want to have logging of multiple devices when you have released your app. Use a dedicated Log Framework (e.g. Log4J) and upload it to a server.
One tip (if you are using Eclipse, and not directly related to question) - Eclipse is very unreliable for viewing logs. For apparently no reason it completely stops displaying logs every now and then. A simple solution is to use command line tools for viewing logs. On Linux you can do :
$adb logcat MyTag:D *:S
If you want to capture logs to a file you can do:
$adb logcat -d > logcat.txt.
Hope this helps!
If you are planning to publish/distribute your application then storing logs in a file is possible but as per my opinion better not a better solution. You can configure online tools from your app.
Catch all sever exceptions and sending all the details regarding that exception. And configure any one logging tool into you application.
You can see log4j http://logging.apache.org/log4j/2.x/ or ACRA http://acra.ch/ or http://www.crittercism.com/
The Android logger's (android.util.Log) output goes to a console that you don't have to maintain. You don't actually have to manage files, just outputs.
You have 5 categories of log:
verbose: use Log.v(tag, message)
debug: use Log.d(tag, message)
info: use Log.i(tag, message)
warning: use Log.w(tag, message)
error: use Log.e(tag, message)
For example:
Log.e("MyActivity", "Oops... caught this exception: " + exception.getMessage());
The LogCat console (this is its name) allows you filtering by log level. This is a ceil filtering. For example, if you filter by 'warnings', you will see all warnings and errors, but not verbose, debug and info messages.
You'll find more details here in the official documentation.
My real intention is this.
Once we go live, if our customers come back and tell us that something crashed or does not work in their android , then how do we debug ?
In the web application, I would ask my server administrator to provide the log files. What do we do with the android application when there is no server error, but something failed in the phone. Is there a way to get logs from the phone.
If you use file for storage logs - it possible problem with performance if the file become big. So you need clean file in time.
As for me best solution use firebase or https://fabric.io/.
We use fabric.io.
Also you can use some wrapper for default Log class. This one https://github.com/JakeWharton/hugo for example
Related
How to get complete logcat from remote users phone?
I came across BUGFENDER and www.REMOTELOGCAT.com ... (didnt use yet.)
I need advice what professionals use for remote logging?
What is the industry standard?
How can I get complete logcat from my client's phone living in another country?
In iOS it gets saved in the phone itself so client can email that log file but whats the solution in android ?
P.S by 'complete logcat' i mean COMPLETE logcat rather than specified logs in code like log.e("some exception occured") as in crashlytics...
I'm not sure how to get the full logcat in Android.
What I can answer is that I'm professional and I use Bugfender for remote logging in iOS and React Native and I know many colleagues using Bufender for Android as well.
I am currently working on an embedded Android application. At present, we have released our device at a small scale and are trying to diagnose some of the problems that users are reporting. Currently, we are writing our logs locally to files on the SD card, but that is obviously a very limited solution.
We have a solution in mind which would involve creating a service to upload our logs automatically, but first I was wondering if there is any standard way to gather logs?
You can use a logging service like Loggly. Install an Android library to log to Loggly, such as Timber-Loggly. You can then start logging.
To make it easier to log to all of your loggers, create a logging function such as:
public static function dLog(String message) {
Log.d(TAG, message);
Timber.d(message);
}
Hey guys I have created an app and provided to people to use it. They cater different issues in the app. I want to capture all Log activities in the file so that they can give it to me and i can examine the problem. i have searched on internet but not getting clear answer. Can any one tell me how can i redirect Android.util.Log output to a text file.
I have tried this
File filename = new File(Environment.getExternalStorageDirectory() + "/gridlog.log");
filename.createNewFile();
String cmd = "logcat -d -f " + filename.getAbsolutePath();
Runtime.getRuntime().exec(cmd);
now to capture Log in file i used
Log.e("HEY ERROR", "HEY THIS IS ERROR");
but it store lot of irrelavant information in the file..and also i works only ones, later if i want to Log info or error it is not capturing it.
Can any android guru help me here.. Thanks
If you want to remotly receieve notifications & error's log / crash reports you can use free services like :
AppHance
BugSense
(I am sure you can find more free service over the web..)
To write the log to SD Card and than to transfer it manually it is not a very clever solution when you have this free cross platform services in my opinion.
Good luck!
A wee bit too late to answer but might help folks in the future. TestFlight's pretty cool free service that allows remote logging, crash reports, beta rollouts, to name a few. Needless to say, these activities can be monitored from your testflight dashboard. Also, supports iOS as well as Android.
I'm trying to play with debug in Android app and, when a breakpoint is encountered, Eclipse shows me a lot of windows, one of which is the "Interactive Console" with a prompt: I think to be able to enter statements and/or other stuff, but it seems to be disabled.
How can I work with it?
Window - Show View - Debug - Display
That will provide you with a window to enter statements and execute/inspect them.
This is a feature that's available in core eclipse platform. It works in most cases for Android based projects as well.
More info on the display view can be found here : http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/views/debug/ref-debug_view.htm
For a nice overview of the debugging features of Eclipse, check out this post : http://www.cavdar.net/2008/09/13/5-tips-for-debugging-java-code-in-eclipse/
The "Interactive Console" within the Debug View of Eclipse is used whenever the debugged program expects some input from the console.
It's possible you have other plugins installed that provide that view, and it's not meant to be used by Android Java code. See here (not accepted answer, but community-favored one).
You can use Logcat for and can see your check points using
android.util.Log.e("","CheckPoint");
You can toast your check points using Toast like:
Toast.makeText(this, "Write here what you want see",1 or 0).show();
1-> long time displaying and 0 for short time.
This toast display in your device screen when programe running.
You can use console screen for seeing output like print statements Ex---
java.lang.System.out.print("Checking");
use
try{
statements...;
}
catch(Exception e){
System.out.println("the error message "+e);
}
will show the error messages.
My customers are having a problem with my app, and I have been unable to reproduce the problem on my development phone. How to debug this problem? The android Log class is great, but my customers do not know how to use 'adb' or the USB debug cable. Is there some way to redirect Log output to a file on the phone's SD card? Then the customer could easily email the log file to me. Even if this redirection requires programming on my part, I could at least distribute a 'debug' version of the app.
Thanks,
Tom
Ask them to install the free app 'Catlog' from the market, which can e-mail you their logcat output. I find 99% of my app users are able to follow simple instructions and get the output one needs!
Try using the Logger class. The procedure is equal to what you would do in a regular Java application:
try {
FileHandler handler = new FileHandler("logfile.log");
Logger logger = Logger.getLogger("com.somename");
logger.addHandler(handler);
} catch (IOException e) {
}
Actual logging to the file could then be done like this:
logger.log(Level.WARNING, "Log message")
Good luck!
There are free and paid services for crash reporting, you might want to check them out..
The only disadvantage is that to send catlog automatically to you, without user interaction, additional permissions for your app is required.
Those are usually READ_LOGS, INTERNET, WRITE_EXTERNAL_STORAGE permissions and depending on type of App that can influence how much your customers trust you. For example if there is no online sync function I would be suprised that myTasksApp requires internet permissions. Anyway.. Here are solutions (list will be updated):
Hockey
Acra
microlog4android
slf4j
log4j
I hope you find this useful.