How to save LogCat contents to file?

前端 未结 10 1251
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 06:57

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 t

相关标签:
10条回答
  • 2020-12-05 07:10

    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.

    0 讨论(0)
  • 2020-12-05 07:12

    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.

    0 讨论(0)
  • 2020-12-05 07:17

    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.
    0 讨论(0)
  • 2020-12-05 07:19
    String filePath = folder.getAbsolutePath()+ "/logcat.txt"; 
    Runtime.getRuntime().exec(new String[]{"logcat", "-f", filePath, "MyAppTAG:V", "*:E"});
    
    0 讨论(0)
  • 2020-12-05 07:22

    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
    
    0 讨论(0)
  • 2020-12-05 07:27

    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

    0 讨论(0)
提交回复
热议问题