I was wondering if there is anyway I can export the same information I get in the LogViewer in Choregraphe into a .txt file by using a Python script loaded into the robot.
I have looked into the documentation of Aldebaran and this is the only thing that seems to get close enough to what i need: http://doc.aldebaran.com/2-4/dev/libqi/guide/py-log-client.html
Did anyone stumbled across the same situation? Can I use something similar to the example given in the link to save the logs into a .txt file?
Thank you in advance for your help!
Using the example for qi.logging
from the docs, you can write the log messages to a file like so.
import qi
import qi.logging
t = open('log.txt','w')
def onMessage(mess):
t.write(str(mess) + '\n') # mess is a dictionary with all known LogMessage information.
def main():
app = qi.Application()
app.start()
logmanager = app.session.service("LogManager")
listener = logmanager.getListener()
listener.onLogMessage.connect(onMessage)
app.run()
if __name__ == "__main__":
main()
Note that the format will be different to what you see in Choregraphe because the log messages are stored in dictionary format. Here's an example message.
{'category': 'ALMemory', 'level': 5L, 'source': ':notify:0', 'location': '36cd8c70-ff69-4017-ac66-c5c711cde253:3106', 'date': 4088131421410L, 'message': 'notifying module: ALBasicAwareness for datachange for key: ALTracker/FindPersonHead', 'id': 2716827L, 'systemDate': 1583368808079483915L}
If you don't need the logs in real-time though, below might be an easier approach.
There are also a number of ways to get the logs manually, depending on what you would like to use the information for. This method is most useful to gather log data for analysis after running a test.
Firstly, you can copy the naoqi system logs directly from where they're written in /var/log/naoqi/servicemanager/system.Naoqi.log
using scp for example. You can find the descriptions of the different logs here.
scp nao@<nao-ip>:/var/log/naoqi/servicemanager/system.Naoqi.log <location-to-store>
You can alternatively run the tool nao-diagnostic
on the robot which will collect all the log files into /home/nao/diagnosis/nao-diagnosis_<date>.tar.xz
. You can them copy this file, unzip it, and you will find the Naoqi log at system-logs/logs/naoqi/servicemanager/system.Naoqi.log