Package: logcatframe
Class for capturing and parsing Android device logs using ADB.pip install logcatframeTested against Windows / Python 3.11 / AnacondaArgs:-adb_path(str):PathtotheADBexecutable.-device_serial(str):SerialnumberofthetargetAndroiddevice.-print_output(bool):Flagtocontrolwhethertoprintlogoutputtotheconsole.-su(bool):Flagindicatingwhethertouse'su'(superuser)forlogcatcommand(defaultisTrue).-clear_logcat(bool):Flagindicatingwhethertoclearexistinglogcatlogsbeforestarting(defaultisTrue).Methods:-__init__(self,adb_path,device_serial,print_output,su=True,clear_logcat=True):InitializesaLogCatFrameinstance.-start_recording(self):StartscapturingAndroiddevicelogsusingthespecifiedADBpathanddeviceserial.If`clear_logcat`isTrue,itclearsexistinglogcatlogsbeforestarting.Thecapturedlogsarestoredintheinstance's `alldata` attribute.-_read_stdout(self,pr):Internalmethodforreadingandprintinglogcatoutput.Usedbythe`start_recording`methodinaseparatethread.-parse_all_data(self,as_pandas=False):Parsesthecapturedlogsintoalistofdictionaries.If`as_pandas`isTrue,convertsthelistintoaPandasDataFrame(requiresPandastobeinstalled).-parse_activities(self):Parsesexecutedactivitiesfromthecapturedlogs.Returnsalistoftuplescontainingtheexecutedcommandandassociatedvariables.-get_short_path_name(long_name):Returnstheshortpathnameforthegivenlongfilename.OnlyapplicableonWindows;onotherplatforms,itreturnstheinputunchanged.fromlogcatframeimportLogCatFrameadblog=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()fromPrettyColorPrinterimportadd_printer# optionaladd_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)']])]