Class for capturing and parsing Android device logs using ADB.
Project description
Class for capturing and parsing Android device logs using ADB.
pip install logcatframe
Tested against Windows / Python 3.11 / Anaconda
Args:
- adb_path (str): Path to the ADB executable.
- device_serial (str): Serial number of the target Android device.
- print_output (bool): Flag to control whether to print log output to the console.
- su (bool): Flag indicating whether to use 'su' (superuser) for logcat command (default is True).
- clear_logcat (bool): Flag indicating whether to clear existing logcat logs before starting (default is True).
Methods:
- __init__(self, adb_path, device_serial, print_output, su=True, clear_logcat=True):
Initializes a LogCatFrame instance.
- start_recording(self):
Starts capturing Android device logs using the specified ADB path and device serial.
If `clear_logcat` is True, it clears existing logcat logs before starting.
The captured logs are stored in the instance's `alldata` attribute.
- _read_stdout(self, pr):
Internal method for reading and printing logcat output.
Used by the `start_recording` method in a separate thread.
- parse_all_data(self, as_pandas=False):
Parses the captured logs into a list of dictionaries.
If `as_pandas` is True, converts the list into a Pandas DataFrame (requires Pandas to be installed).
- parse_activities(self):
Parses executed activities from the captured logs.
Returns a list of tuples containing the executed command and associated variables.
- get_short_path_name(long_name):
Returns the short path name for the given long file name.
Only applicable on Windows; on other platforms, it returns the input unchanged.
from logcatframe import LogCatFrame
adblog = LogCatFrame(
adb_path=r"C:\Android\android-sdk\platform-tools\adb.exe",
device_serial="emulator-5554",
print_output=True,
su=True,
clear_logcat=True,
)
adblog.start_recording()
df=adblog.parse_all_data(as_pandas=True)
listoflist=adblog.parse_all_data(as_pandas=False)
activities=adblog.parse_activities()
from PrettyColorPrinter import add_printer # optional
add_printer(1)
print(df)
print(listoflist)
print(activities)
# [('am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.android.settings/.Settings -b [47,217][161,363]',
# [['act', 'android.intent.action.MAIN'],
# ['cat', '[android.intent.category.LAUNCHER]'],
# ['flg', '0x10200000'],
# ['cmp', 'com.android.settings/.Settings'],
# ['bnds', '[47,217][161,363] (has extras)']]),
# ('am start -f 0x8000 -n com.android.settings/.Settings$PowerUsageSummaryActivity',
# [['flg', '0x8000'],
# ['cmp',
# 'com.android.settings/.Settings$PowerUsageSummaryActivity (has extras)']]),
# ('am start -f 0x8000 -n com.android.settings/.Settings$DisplaySettingsActivity',
# [['flg', '0x8000'],
# ['cmp',
# 'com.android.settings/.Settings$DisplaySettingsActivity (has extras)']]),
# ('am start -a com.android.intent.action.SHOW_BRIGHTNESS_DIALOG -n com.android.systemui/.settings.BrightnessDialog',
# [['act', 'com.android.intent.action.SHOW_BRIGHTNESS_DIALOG'],
# ['cmp', 'com.android.systemui/.settings.BrightnessDialog']]),
# ('am start -f 0x8000 -n com.android.settings/.Settings$SystemDashboardActivity',
# [['flg', '0x8000'],
# ['cmp',
# 'com.android.settings/.Settings$SystemDashboardActivity (has extras)']]),
# ('am start -a android.intent.action.MAIN -n com.android.settings/.SubSettings',
# [['act', 'android.intent.action.MAIN'],
# ['cmp', 'com.android.settings/.SubSettings (has extras)']])]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
logcatframe-0.10.tar.gz
(11.1 kB
view details)
Built Distribution
File details
Details for the file logcatframe-0.10.tar.gz
.
File metadata
- Download URL: logcatframe-0.10.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea190a91d3d2019adaa9d9dc58379627bc3c5dd34a0a533bd860a7a19c4682e9 |
|
MD5 | 300348d9e9538831dd06e5a21cf681e0 |
|
BLAKE2b-256 | 6f7742af0a396590793a6f66dab39a2ff2ed5e805713c349ae802a7d379b6a31 |
File details
Details for the file logcatframe-0.10-py3-none-any.whl
.
File metadata
- Download URL: logcatframe-0.10-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37f5ef688fb3632c433ca5bf610652f3df86bd2492d57fcf90ace92f4abc01c2 |
|
MD5 | 002e5ad62ffd7d5d0f0c7ca060300b1f |
|
BLAKE2b-256 | 6874518fc3abb4bb669da23c044cfcaaab6568182424f7cbfbf69b55f3f671ad |