Log_handler.py 562 B

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