How to save LogCat contents to file?

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

提交回复
热议问题