简体   繁体   中英

Python API implementing a simple log file

I have a Python script that will regulary check an API for data updates. Since it runs without supervision I would like to be able monitor what the script does to make sure it works properly.

My initial thought is just to write every communication attempt with the API to a text file with date, time and if data was pulled or not. A new line for every imput. My question to you is if you would recommend doing it in another way? Write to excel for example to be able to sort the columns? Or are there any other options worth considering?

I would say it really depends on two factors

  1. How often you update

  2. How much interaction do you want with the monitoring data (ie notification, reporting etc)

I have had projects where we've updated Google Sheets (using the API) to be able to collaboratively extract reports from update data. However, note that this means a web call at every update, so if your updates are close together, this will affect performance. Also, if your app is interactive, there may be a delay while the data gets updated. The upside is you can build things like graphs and timelines really easily (and collaboratively) where needed.

Also - yes, definitely the logging module as answered below. I sort of assumed you were using the logging module already for the local file for some reason!

Take a look at the logging documentation. A new line for every input is a good start. You can configure the logging module to print date and time automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM