简体   繁体   English

Android存储关闭日志在哪里?

[英]Where does Android store shutdown logs?

I know that the boot up log can be obtained by pulling out contents of kmsg or dmesg through ADB . 我知道可以通过ADB拉出kmsgdmesg内容来获取启动日志。
But I'm not aware of how to retrieve the shutdown logs in Android as there's no /var folder in Android (place where most desktop linux distros generally store their shutdown logs). 但我不知道如何在Android中检索关机日志,因为Android中没有/var文件夹(大多数桌面Linux发行版通常存储其关机日志的地方)。

So how can I obtain the shutdown logs in Android? 那么如何在Android中获取关机日志?

Look in some locations such as these: 查看以下某些位置:

/proc/last_kmsg
/data/tombstones/
/data/dontpanic/
/data/system/dropbox/

(This list isn't strictly kernel logs, including framework and application logs too, which are also sometimes of interest) (这个列表不是严格的内核日志,包括框架和应用程序日志,有时也有兴趣)

TL;DR : TL; DR
Run command through adb that copies logcat and proc/kmsg to a file and keep it running even when adb disconnects with nohup , disown or setsid . 通过adb运行命令,将logcat和proc / kmsg复制到一个文件并保持运行,即使adb与nohupdisownsetsid断开连接也是如此。 Probably needs busybox, needs root and adb root, too. 可能需要busybox,也需要root和adb root。
setsid cat proc/kmsg > /sdcard/kmsg.txt &
and
logcat -v long -f /sdcard/logcat.txt (somehow only works without setsid ) logcat -v long -f /sdcard/logcat.txt (不知何故只能在没有setsid情况下工作)

Or add normal copy commands to some startup script . 或者将常规复制命令添加到某些启动脚本
/TL;DR / TL; DR

You can constantly copy proc/kmsg and logcat to a file on your android device or a microSD card to get the logs even after adb disconnects. 您可以不断地将proc/kmsglogcat复制到Android设备或microSD卡上的文件中,以便在adb断开连接后获取日志。

You need root access and adb root access for this to work. 您需要root访问权限和adb root访问权限才能生效。 For the latter, use the setting in the developer options if you have a custom rom or the adbd insecure app . 对于后者,如果您有自定义ROM或adbd insecure应用程序 ,请使用开发人员选项中的设置。

After using adb shell to get your android shell, type su to get superuser access. 使用adb shell获取android shell后,输入su以获取超级用户访问权限。

Then you not only need to put an ampersand ( & ) after the command but also make sure that the command keeps running after adb disconnects. 然后,您不仅需要在命令之后放置一个&& ),还要确保在adb断开连接后该命令继续运行。 That is done by nohup , disown or setsid (see here for usage). 这是由nohupdisownsetsid (请参阅此处了解用法)。
If it doesn't work because you don't have these commands, you need to install busybox . 如果由于您没有这些命令而无效,则需要安装busybox
See my question here . 在这里看我的问题。

See here for how to get logcat and kernel logs and print it to some file or merge it. 请参阅此处了解如何获取logcat和内核日志并将其打印到某个文件或合并它。 See developer.android.com/tools/help/logcat.html for parameters for the logcat command. 有关logcat命令的参数,请参阅developer.android.com/tools/help/logcat.html。

In the end you could have a command like setsid cat proc/kmsg > /sdcard/kmsg.txt & for the kernel messages. 最后,您可以使用setsid cat proc/kmsg > /sdcard/kmsg.txt &等命令获取内核消息。

For logcat you could have one of the following commands: logcat -v long -f /sdcard/logcat.txt or logcat -v long > /sdcard/logcat.txt 对于logcat,您可以使用以下命令之一: logcat -v long -f /sdcard/logcat.txtlogcat -v long > /sdcard/logcat.txt

I don't know why, but sometimes it didn't work with setsid and just didn't copy continuously but stopped shortly after executing the command. 我不知道为什么,但有时它不能与setsid ,只是没有连续复制但在执行命令后不久就停止了。 In these situations, it also showed up when entering jobs , which it didn't otherwise. 在这些情况下,它也会在进入jobs ,否则就不会出现。 Then it just worked without setsid , it stayed alive after disconnecting and reconnecting. 然后它只是没有setsid ,它在断开连接和重新连接后保持活着状态。 I guess you must just try when the file does keep getting larger. 我想你必须尝试文件不断变大。 If someone figured out why it is behaving like it is... let me know and I'll edit the answer. 如果有人弄明白为什么它表现得像是......让我知道,我会编辑答案。

Probably adding the commands to a startup script could be a solution for some, too. 将命令添加到启动脚本可能也是一些解决方案。

Hope this helps. 希望这可以帮助。

fightcookie fightcookie

One work around I found for collecting shutdown logs in Android is to run adb pull /proc/kmsg C:\\Logs.txt on the host PC and then switch off the device. 我发现在Android中收集关机日志的一个方法是在主机PC上运行adb pull /proc/kmsg C:\\Logs.txt ,然后关闭设备。 You will get the logs till the USB communication between the host and the device snaps! 您将获取日志,直到主机和设备之间的USB通信快照! I know this is only one case out of the numerous shutdown scenarios but I haven't found satisfactory answers for other cases! 我知道这只是众多停机场景中的一例,但我没有找到其他案例的满意答案!

Newer phones do NOT use any of these locations so if you're reading this article then as of now 较新的手机不使用任何这些位置,所以如果您正在阅读本文,那么截至目前

The kernel crash logs are now in /sys/fs/pstore instead of /proc/last_kmsg 内核崩溃日志现在位于/ sys / fs / pstore而不是/ proc / last_kmsg中

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

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