1234567891011121314151617181920212223242526272829303132333435363738 |
- import datetime
- class LogList():
- def __init__(self, line_count):
- self.log_list = list()
- self.read_index = 0
- self.write_index = 0
- self.line_count = line_count
- def add_item(self, item):
- self.log_list.append(item)
- self.write_index += 1
- if len(self.log_list) > self.line_count:
- 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(line_count = 100):
- global _log_handler
- if not _log_handler:
- _log_handler = LogList(line_count)
- return _log_handler
|