简体   繁体   English

如何在我的设备上获取logcat以显示来自所有进程的日志

[英]How can I get logcat on my device to show logs from all processes

I'm trying to write an app that reads all logs on my device. 我正在尝试编写一个能够读取设备上所有日志的应用程序。 I've got a client/service architecture, and I see log messages from both the client and service processes but I don't see any messages from any other applications on the phone (I do see other messages using the desktop logcat). 我有一个客户端/服务架构,我看到来自客户端和服务进程的日志消息,但我没有看到来自手机上任何其他应用程序的任何消息(我确实看到使用桌面logcat的其他消息)。

Do I need root? 我需要root吗?

Code Snippets 代码片段

Manifest 表现

<uses-permission android:name="android.permission.READ_LOGS" />

Log Reader 日志阅读器

Runtime.getRuntime().exec("logcat -c").waitFor();

Process process = Runtime.getRuntime().exec("logcat -v long *:*");
BufferedReader reader = 
    new BufferedReader(new InputStreamReader(process.getInputStream()));
while (true) {
    String nextLine = reader.readLine();
    if (!nextLine.contains("LogWatcher-D")) {
        Log.w("LogWatcher-D", "See: " + nextLine);
    }

    // Process line
}

On Android 4.1+, you can only access log messages logged by your process, unless you hold the READ_LOGS permission. 在Android 4.1+上,您只能访问由进程记录的日志消息,除非您持有READ_LOGS权限。 That permission requires either that your app be signed by the same signing key that signed the device's firmware, or that your app is installed on the system partition. 该权限要求您的应用程序必须使用签署设备固件的相同签名密钥进行签名,或者您的应用程序安装在系统分区上。

要以编程方式从其他应用程序读取日志,您需要在所有apks的清单文件中分配相同的android:sharedUserId。

There is another way to access all logs for all applications without root. 还有另一种方法可以访问没有root的所有应用程序的所有日志。 It requires enabling remote debugging. 它需要启用远程调试。 Take a look at the open source rootless Logcat app . 看看开源无根Logcat应用程序

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

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