Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

logcat

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).

Do I need 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
}
like image 328
Hounshell Avatar asked Apr 25 '13 19:04

Hounshell


People also ask

How do I get Logcat on my phone?

To gather logs (logcat) from an android phone, follow either one of the following processes. Install Android SDK from http://developer.android.com/sdk/index.html. Make sure platform-tools is included (http://developer.android.com/sdk/installing/adding-packages.html). Enable USB Debugging on your device.

How can I get logs on my Android phone?

Navigate to device settings and enable Developer Options (see section for ADB logs) Navigate to Developer Options and tap on Take/Submit Bug Report. Select Full Report when prompted to get the full device info along with the logs.

Why is my Logcat not showing anything in Android?

Solution 1: Restarting your Android StudioIn your IDE Go to File > Invalidate Caches and Restart > Invalidate and Restart. This Solution will clear all the caches of Android studio IDE and restart it automatically, By the method, there are 80% change that Logcat will start work as before.


1 Answers

On Android 4.1+, you can only access log messages logged by your process, unless you hold the READ_LOGS permission. 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.

like image 90
CommonsWare Avatar answered Oct 23 '22 16:10

CommonsWare