[android] How to save LogCat contents to file?

I've added debug strings (using Log.d()) and want to see them in context from the contents of logCat. The "save" icon for LogCat has a "Save selected items" hint, but there's got to be a quick way to just save the entire contents, or select the entire contents, but I don't see how to do it.

The answer is


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.


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


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

An additional tip if you want only the log shown in the past half hour with timestamps, or within another set time. Adjust date format to match your system. This one works on Ubuntu 16.04LTS:

adb shell logcat -d -v time -t "$(date '+%m-%d %H:%M:%S.%3N' -d '30 minutes ago')" > log_name.log

Click in the logcat window (on a log even). Followed by "Ctrl + A" (select all). Then either "Right click with the mouse" or "Ctrl +C" (copy). Then paste it anywhere you like using any editor you like. One could also delete the logcat output before the logs relevant to us appear (before we start testing our use case) to get only relevant logs in the logcat.


If you are in the console window for the device and if you use Teraterm, then from the Menu do a File | Log and it will automatically save to file.


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.

String filePath = folder.getAbsolutePath()+ "/logcat.txt"; 
Runtime.getRuntime().exec(new String[]{"logcat", "-f", filePath, "MyAppTAG:V", "*:E"});

Additional tip for the programmatic approach:

String filePath = Environment.getExternalStorageDirectory() + "/logcat.txt";
Runtime.getRuntime().exec(new String[]{"logcat", "-f", filepath, "MyAppTAG:V", "*:S"});

This opens a continuous output stream between logcat and the file provided. This can result in a deadlock if you then waitFor the Process returned by exec, or an exception if the provided file is prematurely disposed.

I found that including the "-d" flag simply dumps logcat and closes the connection, which prevents the above behavior.


Open command prompt and locate your adb.exe(it will be in your android-sdk/platform-tools)

adb logcat -d > <path-where-you-want-to-save-file>/filename.txt

If you omit path, it will save logcat in current working directory

The -d option indicates that you are dumping the current contents and then exiting. Prefer notepad++ to open this file so that you can get everything in a proper readable format.


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to android-emulator

flutter run: No connected devices How to remove the Flutter debug banner? Android Studio AVD - Emulator: Process finished with exit code 1 Android Studio Emulator and "Process finished with exit code 0" Run react-native on android emulator ERROR Android emulator gets killed Error while waiting for device: Time out after 300seconds waiting for emulator to come online Unfortunately Launcher3 has stopped working error in android studio? updating Google play services in Emulator Android Studio emulator does not come with Play Store for API 23

Examples related to eclipse-plugin

Could not calculate build plan: Plugin org.apache.maven.plugins:maven-jar-plugin:2.3.2 or one of its dependencies could not be resolved JavaScript Editor Plugin for Eclipse How to see my Eclipse version? No server in windows>preferences Cannot load 64-bit SWT libraries on 32-bit JVM ( replacing SWT file ) An error occurred while collecting items to be installed (Access is denied) Maven in Eclipse: step by step installation How to save LogCat contents to file? How can I change Eclipse theme? What to do about Eclipse's "No repository found containing: ..." error messages?

Examples related to android-logcat

Android Studio - ADB Error - "...device unauthorized. Please check the confirmation dialog on your device." Restore LogCat window within Android Studio Meaning of Choreographer messages in Logcat How to save LogCat contents to file? Filter LogCat to get only the messages from My Application in Android? Filter output in logcat by tagname Logcat not displaying my log calls