How to save LogCat contents to file?

前端 未结 10 1252
没有蜡笔的小新
没有蜡笔的小新 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:28

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

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

    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.

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

    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.

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