I have some log statements in my app that are shown in Android Studio's LogCat if the app runs on an emulator device. E.g.:
public VocabularyTrainerModelImpl() {
...
Log.d(TAG, "First line index is -1");
...
}
If understood it right the one suggested to run:
$ adb logcat -d > log.txt
to get the log file from a real device. How do I get the logfile from an Android device?
I connected my phone via USB to my PC and ran this command. But I couldn't see my log messages. How do I get them? If possible without any additional installations.
There is a bug in the app which occurs very seldom. So in this case I want to connect the phone to PC, extract the log file and analyze it.
I've found a solution here: https://stackoverflow.com/a/22802081/971355
The log file isn't created automatically. I have to write it myself by running logcat from the app.
public static void printLog(Context context){
String filename = context.getExternalFilesDir(null).getPath() + File.separator + "my_app.log";
String command = "logcat -f "+ filename + " -v time *:V";
Log.d(TAG, "command: " + command);
try{
Runtime.getRuntime().exec(command);
}
catch(IOException e){
e.printStackTrace();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With