This guide goes over the best practice to send and receive device logs as well as view them at Upswift platform.
Time to read:
This guide goes over the best practice to send and receive device logs as well as view them at Upswift platform. The best practice guidelines are used Upswift General API to send logs from connected devices to Upswift platform in the quickest way.
Send device logs approach
Upswift provides an easy-to-use way to send device logs from any type and view/download them from Upswift platform. These logs may help you to have a better understanding of the product behavior in the long-run, also, can be useful for debugging issues and investigation.
As a best practice, we would like to send daily/weekly logs of our device application, this can be done by using a separate script that will run by service manager/crontab, or inside the application code itself. In this best practice guide, we will create a weekly logs push script that runs once a week from each device.
Those guidelines require the device to be connected to Upswift platform. For more information about the Logs feature, read Upswift docs.
1. Create a python script (is it possible to work with any other programing language with HTTP library).
This script pulls Upswift account tokens, take the path of the log file and send it to Upswift servers. Make sure to change the values of FILE_NAME & FILE_PATH as needed.
2. To run our script each day or week, we will use crontab software and schedule when to call the python script.
Here is a ready-to-use command you need to run on the device terminal to creates a cron job:
echo "* * 1 * * python /home/app/send_logs.py" >> /etc/crontab
Make sure to change the path (in red) which indicates the place you store the python script.
From now on, your device will run the python script once a day.
3. Under the 'Devices' category, each device has a Log section where you will be able to view and download the received device logs.