Linux Android 在哪里存储关机日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6071547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:10:10  来源:igfitidea点击:

Where does Android store shutdown logs?

androidlinuxlogginglinux-kernel

提问by Pavan Manjunath

I know that the boot up log can be obtained by pulling out contents of kmsgor dmesgthrough ADB.
But I'm not aware of how to retrieve the shutdown logs in Android as there's no /varfolder in Android (place where most desktop linux distros generally store their shutdown logs).

我知道,开机日志可拉出的内容来获得kmsgdmesg通过ADB
但我不知道如何在 Android 中检索关机日志,因为 Android 中没有/var文件夹(大多数桌面 Linux 发行版通常存储其关机日志的地方)。

So how can I obtain the shutdown logs in Android?

那么如何在Android中获取关机日志呢?

采纳答案by Pavan Manjunath

One work around I found for collecting shutdown logs in Android is to run adb pull /proc/kmsg C:\Logs.txton the host PC and then switch off the device. You will get the logs till the USB communication between the host and the device snaps! I know this is only one case out of the numerous shutdown scenarios but I haven't found satisfactory answers for other cases!

我发现在 Android 中收集关机日志的一种解决方法是adb pull /proc/kmsg C:\Logs.txt在主机 PC 上运行,然后关闭设备。您将获得日志,直到主机和设备之间的 USB 通信中断!我知道这只是众多关机场景中的一个案例,但我还没有找到其他案例令人满意的答案!

回答by Chris Stratton

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)

(这个列表不是严格的内核日志,也包括框架和应用程序日志,有时也很有趣)

回答by xuiqzy

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, disownor setsid. Probably needs busybox, needs root and adb root, too.
setsid cat proc/kmsg > /sdcard/kmsg.txt &
and
logcat -v long -f /sdcard/logcat.txt(somehow only works without setsid)

TL;DR
通过 adb 运行命令,将 logcat 和 proc/kmsg 复制到一个文件中,并保持它运行,即使 adb 与nohup,disown或断开连接setsid。可能需要busybox,也需要root和adb root。
setsid cat proc/kmsg > /sdcard/kmsg.txt &

logcat -v long -f /sdcard/logcat.txt(不知何故只适用于没有setsid

Or add normal copy commands to some startup script.
/TL;DR

或者在一些启动脚本中添加普通的复制命令。
/TL;博士

You can constantly copy proc/kmsgand logcatto a file on your android device or a microSD card to get the logs even after adb disconnects.

即使在 adb 断开连接后,您也可以不断复制proc/kmsg并复制logcat到 Android 设备或 microSD 卡上的文件以获取日志。

You need root access and adb root access for this to work. For the latter, use the setting in the developer options if you have a custom rom or the adbd insecure app.

您需要 root 访问权限和 adb root 访问权限才能使其工作。对于后者,如果您有自定义 rom 或 adbd insecure 应用程序,请使用开发人员选项中的设置。

After using adb shellto get your android shell, type suto 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. That is done by nohup, disownor setsid(see herefor usage).
If it doesn't work because you don't have these commands, you need to install busybox.
See my question here.

那么你不仅需要&在命令后面加上一个与号 ( ) ,还要确保在 adb 断开连接后命令继续运行。这是由nohup, disownor完成的setsid(见这里的用法)。
如果因为没有这些命令而不起作用,则需要安装busybox在这里
看到我的问题。

See herefor how to get logcat and kernel logs and print it to some file or merge it. See developer.android.com/tools/help/logcat.html for parameters for the logcat command.

请参阅此处了解如何获取 logcat 和内核日志并将其打印到某个文件或合并它。有关 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.txtor 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 setsidand just didn't copy continuously but stopped shortly after executing the command. In these situations, it also showed up when entering jobs, which it didn't otherwise. Then it just worked without setsid, it stayed alive after disconnecting and reconnecting. 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.

我不知道为什么,但有时它不起作用,setsid只是没有连续复制,但在执行命令后不久就停止了。在这些情况下,它也会在输入 时出现jobs,否则它不会出现。然后它在没有 的情况下工作setsid,在断开连接并重新连接后它仍然存在。我想你必须在文件不断变大时尝试。如果有人弄清楚为什么它的行为如此......请告诉我,我会编辑答案。

Probably adding the commands to a startup script could be a solution for some, too.

可能将命令添加到启动脚本也可能是一些解决方案。

Hope this helps.

希望这可以帮助。

fightcookie

打架饼干

回答by aryanisno1

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