简体   繁体   English

如何在Android Studio中从连接的设备读取存储的日志

[英]How to read the STORED logs from an attached device in Android Studio

I need to read the logs that are stored in a device that I have attached by USB. 我需要阅读通过USB连接的设备中存储的日志。 It's set up for debugging. 它是为调试而设置的。 I run the Device File Explorer and it shows all the files. 我运行设备文件资源管理器,它显示了所有文件。 But where are the log files hidden? 但是日志文件隐藏在哪里?

AFAIK, the Android System does not keep a Log File, rather it has a temp buffer which contains logs. AFAIK,Android系统不保留日志文件,而是具有一个包含日志的临时缓冲区。

Approach 1:Write logs to file in internal storage through code 方法1:通过代码将日志写入内部存储中的文件

You need to write logs to the device by yourself. 您需要自己将日志写入设备。 There are libraries like logback-android which can assist in doing so. 有像logback-android这样的库可以帮助您。 You just need to create proper configuration in order to write logs on the device storage. 您只需要创建适当的配置即可在设备存储上写入日志。

Approach 2: Write logs to file using adb command 方法2:使用adb命令将日志写入文件

Since you are connected through USB you can do 由于您通过USB连接,因此您可以

adb logcat -d > logcat.txt

The above command stores file on PC and not on device. 上面的命令将文件存储在PC上,而不存储在设备上。 Its in the same directory pointed by the command prompt 它在命令提示符指向的同一目录中

Approach 3: Use Android Studio 方法3:使用Android Studio

Connect your device to PC and run Android studio. 将您的设备连接到PC并运行Android Studio。 At the bottom, you have logcat tab. 在底部,您有logcat标签。 You can view the logs and also save them to a text file. 您可以查看日志,也可以将它们保存到文本文件中。


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM