How to show the logs of Appium server programmatically?

Hi guys,

I am using Python 3.7.

I finally managed to launch Appium programmatically. But I can’t see the log anymore.
I was used to see the log from Appium view. Now I get lost. I need your help please.
I found this doc:
http://appium.io/docs/en/commands/session/logs/get-log/#get-logs

Which says to add this line:
logs = driver.get_log(‘driver’);

It looks weird for me to add a “;” at the end of a python line (but I am newbie, so I did as it said).

But it didn’ show anything. So I added this line:
print(f"Logs : {logs}")

And it didn’t show anything again.

Does any Python expert can tell me the lines of code to store or display the logs of Appium server.

Thanks.

Kind regards

First I would try:
log_types = driver.log_types();
Then I would try:
logs = driver.get_log(‘server’);
You should be able to request any of the log types returned from the first call.

Cory

1 Like

Sorry, what do you mean by ‘server’

I have only these lines to start server:
appium_service = AppiumService()
appium_service.start()

Do you mean the ip:port
Example:
logs = driver.get_log(‘127.0.0.1:4723’)
?

Thanks for your help

When requesting the logs you specify which ‘type’ of logs you want.
You can get a list of what type of logs are available with the log_types(); but it is likely you are interested in requesting the ‘server’ type logs if that makes sense? Thus the call driver.get_log(‘server’); would return the logs your appium server you launched programmatically and created a session with.

The logs are only available if you have the security settings to allow this. It seems you have to start the server with a few flags --relaxed-security , or be more specific about it by reading this link. https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/security.md

Thank you for your help.
I educated myself more about python logs And I made some experiments with 3 ways to sart Appium server before to come back to you.

I tried by this way:
appium_service = AppiumService()
appium_service.start()

But I don’t see any log. I guess I need to modify the python file of appium_service method.

So I tried to start appium server with command (I added the flag of scurity you suggested):
os.system("start /B start cmd.exe @cmd /k appium --relaxed-security --log-timestamp --log appium.log -a 127.0.0.1 -p 4728")
I could see some logs in terminal but not so much than Appium GUI server.

To show you the difference, I commented the lines of code which start Appium server, and I start it by hand with Appium GUI.

As you can see Appium GUI logs give more information to debug my code.

What should I do to display same info in Appium terminal than Appium GUI?
What should I do to display same info in ‘appium_service.start()’ than Appium GUI?

Thanks a lot again for your help.

1 Like

–log-level debug:debug --debug-log-spacing

Thank you. I should add these flags in the windows command or sOmewhere in the code of appium_service?

Gautier
It looks like you run appium inside your test tool, so just adding those 2 flags should do what you want. What worries me, is that you probably tried that already and did not get joy the first time.

hello fgh
try adding arguments to your code

option 1
import os
os.system(“start /B start cmd.exe @cmd /k appium -a 0.0.0.0 -p 4723 -pa /wd/hub”)
still don’t know how to stop appium

option 2
from appium.webdriver.appium_service import AppiumService
appium_service = AppiumService()
appium_service.start(args=[’–automation-name’, ‘Appium’, ‘-a’, ‘localhost’, ‘-p’, ‘4723’, ‘-pa’, ‘/wd/hub’, ‘-bp’, ‘4723’])
appium_service.stop()