How can one use the logging facility in robots written in Python

I have a simple python:

from RPA.Windows import Windows
from robot.libraries.BuiltIn import BuiltIn

lib = Windows()

wind = lib.list_windows()
for winde in wind:
print(“title=”, winde[‘title’], " name=", winde[‘name’])

If I execute this one rhen I get no log.html file where I could see the “List Windows” Keyword.
And how could I use the log for additional information written by Python

Hi @herbert.semmelmayer

Indeed, when running RF-like robots (with the robot library) such an additional log file is created.
With Python, you have to manage the logging yourself and fortunately all our libraries are using this at the moment, thus you should see the output in the console.

Thank you for the information!

I have added the loggin to my coding but still there are no log entries of RPA.
What have I to do to have a common log of my robot in python and the log entries of the RPA keywords
which I have seen before not using python for my robot.

my robot:
import logging
from RPA.Windows import Windows
from robot.libraries.BuiltIn import BuiltIn

lib = Windows()
logging.basicConfig(filename=“py.log”, encoding=“UTF-8”, level=logging.DEBUG, format=“%(asctime)s %(levelname)s %(message)s”)
logging.debug(“start List”)
logging.info(“Test logging”)
logging.warning(“Just to see a warning”)
logging.error(“Can not see RPA entries”)
wind = lib.list_windows()
for winde in wind:
print(“title=”, winde[‘title’], " name=", winde[‘name’])

The log looks like :
2023-04-04 11:14:55,633 DEBUG start List
2023-04-04 11:14:55,633 INFO Test logging
2023-04-04 11:14:55,633 WARNING Just to see a warning
2023-04-04 11:14:55,633 ERROR Can not see RPA entries

Hello!
After using this code line at the start I can see log entries from RPAframework:

logging.basicConfig(filename=“py.log”, encoding=“UTF-8”, level=logging.DEBUG, format=“%(asctime)s %(name)s %(levelname)s %(message)s”)
Problem is solved

2 Likes