logHandler.py 666 B

12345678910111213141516171819202122232425262728293031
  1. import datetime
  2. class LogList():
  3. def __init__(self):
  4. self.log_list = list()
  5. self.read_index = 0
  6. def add_item(self,*args):
  7. args = [str(i) for i in args]
  8. item = " ".join(args)
  9. item = str(datetime.datetime.now())+" "+str(item)
  10. self.log_list.append(item)
  11. if len(self.log_list) > 100:
  12. self.log_list.pop(0)
  13. def get_log_list(self):
  14. return self.log_list
  15. def get_new_items(self):
  16. items = self.log_list[self.read_index:]
  17. self.read_index = len(self.log_list)
  18. return items
  19. _log_handler = None
  20. def get_log_handler():
  21. global _log_handler
  22. if not _log_handler:
  23. _log_handler = LogList()
  24. return _log_handler