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.
问题:
回答1:
You are not getting the answer you are looking for, are you.
Two ways to do what you want:
1) 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).
2) when focus is in logcat messages window, type control-A, this will select all messages. Then save etc. etc.
回答2:
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
File will be created of the name "logcat.txt" in the platform-tools folder. you can change the name according to your interest. enjoy
回答3:
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.
回答4:
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
回答5:
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.
回答6:
Use logcat tool with -d
or -f
switch and exec() method.
回答7:
String filePath = folder.getAbsolutePath()+ "/logcat.txt";
Runtime.getRuntime().exec(new String[]{"logcat", "-f", filePath, "MyAppTAG:V", "*:E"});
回答8:
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.
回答9:
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.
回答10:
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