PythonRemoteServer icon indicating copy to clipboard operation
PythonRemoteServer copied to clipboard

Support logging using `robot.api.logger` and `logging` APIs

Open vkruoso opened this issue 10 years ago • 5 comments

It would be a nice feature to have if you could have a library that uses the robot.api.logger to log messages to just work when used in a remote server using the PythonRemoteServer.

vkruoso avatar Jul 02 '15 13:07 vkruoso

I am looking for this 'feature' too. It seems very strange not to support Robots own logging in a Robot server. I know python "print" output is picked up. But, as an example, I run the OperatingSystem Copy File keyword, but the INFO message gets lost on the remote system somewhere. This needs to be reported back to the output of the calling script. I tried registering my own logger in my remote library as follows: class RFremoteLogger(Logger): # Inherit from robot.output.logger.Logger def message(self, record): print record . . . if name == 'main': from robotremoteserver import RobotRemoteServer LOGGER.register_logger(RFremoteLogger) RobotRemoteServer(MyRemoteLib(), *sys.argv[1:])

But this didn't work. No error, but also no output. I tried some other variations but no luck. Any suggestions how to get the output?

VernonCrabtree avatar Jul 14 '15 10:07 VernonCrabtree

For anyone else coming here: I solved it with this bit of code in my remote library:

from robot.api import logger

def remote_log_message(message,level,html=False): print '{} {}'.format(level, message)

logger.write = remote_log_message

This works because most Robot libraries import logger from robot.api - where we replace the definition of write.

VernonCrabtree avatar Jul 15 '15 20:07 VernonCrabtree

@VernonCrabtree Thank you, it's really a easy and best solution.

swordfly avatar Dec 07 '16 08:12 swordfly

Yep, official support for robot.api.logger as well as for Python's logging module would be nice.

pekkaklarck avatar Jan 09 '17 15:01 pekkaklarck

@VernonCrabtree : works like a charm. Nice workaround.

conrados avatar Jun 06 '19 16:06 conrados