12345678910111213141516171819202122232425262728293031323334353637 |
- import datetime
- class LogList():
- def __init__(self):
- self.log_list = list()
- self.read_index = 0
- self.write_index = 0
- def add_item(self, item):
- self.log_list.append(item)
- self.write_index += 1
- if len(self.log_list) > 100:
- self.log_list.pop(0)
- def log_and_print(self, *args):
- args = [str(i) for i in args]
- item = " ".join(args)
- item = str(datetime.datetime.now())+" "+str(item)
- self.add_item(item)
- print(item)
- def get_log_list(self):
- return self.log_list
- def get_new_items(self):
- items = self.log_list[self.read_index:]
- self.read_index = self.write_index
- return items
- _log_handler = None
- def get_log_handler():
- global _log_handler
- if not _log_handler:
- _log_handler = LogList()
- return _log_handler
|