Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the app log from a real Android device?

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.

like image 661
ka3ak Avatar asked Dec 09 '25 11:12

ka3ak


1 Answers

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();
    }
}
like image 175
ka3ak Avatar answered Dec 11 '25 23:12

ka3ak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!