The Military Mode-S page

Clean up of old logs

With PlanePlotter generating a new log file every day, you will quickly end up with a lot of old log files. Of course it’s all up to you to decide whether to keep these indefinitely, or delete old files after some time. I decided to keep log files for no more than one month, and then delete them automatically. For this I wrote another script, this time in the Python language, which runs daily on the PlanePlotter computer. Not only does this script remove old log files, but also other files and “garbage” PlanePlotter writes to the log folder. On Windows, you could do the same in PowerShell, PHP, or any other suitable script language. Again, as reference only:

#!/usr/bin/python
import glob, os, time
 
# array with PlanePlotter log directories to clean (with ending /)
LOGDIRS = ['<path to your log folder>',
           '<path to other log folder (as as many as you need)>']
 
# array with log types (file name template and after how many days to delete, 0 = immediately)
LOGS = [['gstestYYMMDD.txt', 1],
        ['multilatYYMMDD.log', 1],
        ['planeplotterYYMMDD.log', 1],
        ['pp_reportYYYYMMDD99.log', 0],
        ['pp_reportYYYYMMDD99.sqb', 31],
        ['pp_reportYYYYMMDD99.sqb-journal', 1],
        ['pp_report_YYMMDD99.txt', 0],
        ['RTLYYMMDD99.log', 1]]
 
# array with additional single files also to delete
SINGLE = ['ipconfigbat.bat',
          'lookup.vbs',
          'metar.txt',
          'readmelog.txt',
          'restartlog.txt']
 
# process all log directories
for LOGDIR in LOGDIRS:
 
   # process all log types
   for LOG in LOGS:
 
      # determine newest of this log type to be deleted
      NEWEST = LOG[0].replace('9', '')
      TIMESTAMP = time.time() - (LOG[1] * 86400)
      if NEWEST.find('YYYY') > -1:
         NEWEST = NEWEST.replace('YYYYMMDD', time.strftime('%Y%m%d', time.localtime(TIMESTAMP)))
      else:
         NEWEST = NEWEST.replace('YYMMDD', time.strftime('%y%m%d', time.localtime(TIMESTAMP)))
 
      # delete all logs of this type as old or older than the just determined log
      TEMPLATE = LOG[0]
      MAPPING = [('YY','??'),('MM','??'),('DD','??'),('99','??')]
      for ORG, NEW in MAPPING:
         TEMPLATE = TEMPLATE.replace(ORG, NEW)
      for FILENAME in glob.glob(LOGDIR + TEMPLATE):
         if FILENAME < (LOGDIR + NEWEST):
            os.remove(FILENAME)
 
      # process any additional files
      for FILENAME in SINGLE:
         if os.path.isfile(LOGDIR + FILENAME):
            os.remove(LOGDIR + FILENAME)
 
# end of script

Concluding…?

So, there it is, more or less. Maybe you’re inspired, maybe not, maybe you’re slightly daunted by the prospect of having to set up all that is mentioned here.. But at least now you know how it’s done. And if you want to pursue this yourself, then my only comment is: “good luck and have fun with it! (you’re on your own)” 😉

Marco