How do I get the "message" element in python from driver.get_log(‘logcat’)


I am writing a script on appium, and I want to detect the if the android application exited with code 0, 1 or 2, then I will need to print some texts.

I can see on the Appium server log that the exited with code 0, but just wondering how do I get this information in my code.

[Instrumentation] Time: 3,603.334


[Instrumentation] OK (1 test)

[Instrumentation] The process has exited with code 0

I know that there is an appium option that you can pass the server which directs all the logs to a file of your chose the, you can just import the file to your program and look for a certain string which indicates about your exit code.
appium CLI arguments:,%2Dg%2C%20%2D%2Dlog,-null
see the –log option

I think I am able to figure out a way .

log = driver.get_log(‘logcat’)

I am trying to access the appium logcat "message"element with python, I am not super familiar with python and appium.

It seems like the get_log(‘logcat’) with return a json type of result, and I want to put that in dictionary and access the “message” element, I have been googling a lot still not sure how to do it. Hopefully someone can help me out a bit on that.

log = driver.get_log('logcat')
logcat_string = json.dumps(log)
logcat_item = json.loads(logcat_string)

appium_message = logcat_item["message"]
print("Appium message "+appium_message)

appium_jsonlog = open("appium_log.json", "w")
appium_jsonlog .close()