Logcat can show the process ID (PID) that outputs the log message.
- For command-line:
adb logcat will use threadtime by default, which shows the PID
- For Android Studio:
- Open the Logcat window
- From the toolbar (on the left-side), click the Logcat Header (cogwheel) button
- If the toolbar is not shown, click the Show Options Menu (cogwheel) button on the top-right corner, then choose Show Toolbar
- On Configure Logcat Header dialog, check Show process and thread IDs, then press OK
By default, logcat will show the log in the following format:
date time PID-TID/package priority/tag: message
With the PID, it is possible to identify the source with ps command with -p flag to pinpoint the source, i.e. adb shell ps -p [PID]. The command will show the package name or the executable name.
Example
The logcat returned the following message
2020-07-08 22:06:16.002 18510-18510/? I/ScreenEventHandler: Received Broadcast ACTION_SCREEN_ON
The PID is 18510.
Calling adb shell ps -p 18510 returned the following
USER PID PPID VSIZE RSS WCHAN PC NAME
u0_a107 18510 15708 1006092 44320 sys_epoll_ 00000000 S com.asksven.betterbatterystats
Thus, the message was written by com.asksven.betterbatterystats (BetterBatteryStats)