How to save LogCat contents to file?
To save the Log cat content to the file, you need to redirect to the android sdk's platform tools folder and hit the below command
adb logcat > logcat.txt
In Android Studio, version 3.6RC1, file will be created of the name "logcat.txt" in respective project folder. you can change the name according to your interest. enjoy
You are not getting the answer you are looking for, are you.
Two ways to do what you want:
- Right-click in the logcat messages window, choose select all. Then your save will be all logcat messages in that window (including the ones scrolled out of view).
- When focus is in logcat messages window, type control-A, this will select all messages. Then save etc. etc.
In addition to answer by Dinesh Prajapati, Use
adb -d logcat <your package name>:<log level>
where -d is for device and you may also choose -e instead for emulator log and log level is a/d/i/v/e/w etc.
Now your command goes like:
adb -d logcat com.example.example:V > logfileName_WithPath.txt
To save LogCat log to file programmatically on your device use for example this code:
String filePath = Environment.getExternalStorageDirectory() + "/logcat.txt";
Runtime.getRuntime().exec(new String[]{"logcat", "-f", filepath, "MyAppTAG:V", "*:S"});
"MyAppTAG:V"
sets the priority level for all tags to Verbose (lowest priority)
"*:S"
sets the priority level for all tags to "silent"
More information about logcat here.
Use logcat tool with -d
or -f
switch and exec() method.
Saving to a file on the host computer:
exec( "adb logcat -d > logcat.log" ) // logcat is written to logcat.log file on the host.
If you are just saving to a file on the device itself, you can use:
exec( "adb logcat -f logcat.log" ) // logcat is written to logcat.log file on the device.