-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
32 lines (32 loc) · 1.29 KB
/
Copy pathlogger.py
File metadata and controls
32 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Models
class Message:
def __init__(self,event):
self.event=event
class SendMessage(Message):
def __init__(self,event):
super().__init__(event)
def __str__(self):
if not self.event.receiver:
if self.event.code==Models.APPLY_EVENT:
return str(self.event.startTime) + ":节点" + str(self.event.sender.id) + "申请发言"
return str(self.event.startTime)+":节点"+str(self.event.sender.id)+"通知冲突"
return str(self.event.startTime)+":节点"+str(self.event.sender.id)+"发送了"+str(self.event.body)+"向"+str(self.event.receiver.id)
class ReceiveMessage(Message):
def __init__(self,event):
super().__init__(event)
def __str__(self):
return str(self.event.endTime) + ":节点" + str(self.event.receiver.id) + "接受了" + str(self.event.body) + "从" + str(
self.event.sender.id)
class Logger:
# 单例
def __new__(cls, *args, **kwargs):
if not hasattr(cls, 'instance'):
cls.instance = super(Logger,cls).__new__(cls)
return cls.instance
def __init__(self):
self.messageList=[]
def log(self,message):
self.messageList.append(message)
def output(self):
for message in self.messageList:
print(str(message))