code: def statsAndLoggingAggregator(cls, jobStore, stop, config):
          
          #  Overall timing
          startTime = time.time()
          startClock = getTotalCpuTime()
  
          def callback(fileHandle):
              statsStr = fileHandle.read()
              if not isinstance(statsStr, str):
                  statsStr = statsStr.decode()
              stats = json.loads(statsStr, object_hook=Expando)
              try:
                  logs = stats.workers.logsToMaster
              except AttributeError:
                  # To be expected if there were no calls to logToMaster()
                  pass
              else:
                  for message in logs:
                      logger.log(int(message.level),
                                 'Got message from job at time %s: %s',
                                 time.strftime('%m-%d-%Y %H:%M:%S'), message.text)
              try:
                  logs = stats.logs
              except AttributeError:
                  pass
              else:
                  # we may have multiple jobs per worker
                  jobNames = logs.names
                  messages = logs.messages
                  cls.logWithFormatting(jobNames[0], messages,
                                        message='Received Toil worker log. Disable debug level logging to hide this output')
                  cls.writeLogFiles(jobNames, messages, config=config)
  
          while True:
              # This is a indirect way of getting a message to the thread to exit
              if stop.is_set():
                  jobStore.readStatsAndLogging(callback)
                  break
              if jobStore.readStatsAndLogging(callback) == 0:
                  time.sleep(0.5)  # Avoid cycling too fast
  
          # Finish the stats file
          text = json.dumps(dict(total_time=str(time.time() - startTime),
                                 total_clock=str(getTotalCpuTime() - startClock)), ensure_ascii=True)
          jobStore.writeStatsAndLogging(text)
docs: The following function is used for collating stats/reporting log messages from the workers.
          Works inside of a thread, collates as long as the stop flag is not True.