Debug the debug function

This commit is contained in:
Loic Guegan 2022-08-24 12:09:06 +02:00
parent 371749159b
commit 5384940ca7

View file

@ -76,12 +76,10 @@ class Simulator:
""" """
Log all the informations for debugging Log all the informations for debugging
""" """
stdout_save = sys.stdout
with open(self.debug_file_path, "a") as debug_file: with open(self.debug_file_path, "a") as debug_file:
sys.stdout = debug_file debug_file.write("-----------------------------------------------\n")
print("-----------------------------------------------") debug_file.write("Started since {}s\n".format(round(time.time()-self.startat,2)))
print("Started since {}s".format(round(time.time()-self.startat,2))) debug_file.write("Simulated time {}s (or more precisely {}s)\n".format(self.time_truncated,self.time))
print("Simulated time {}s (or more precisely {}s)".format(self.time_truncated,self.time))
states=dict() states=dict()
timeout_mode=list() timeout_mode=list()
sharing=dict() sharing=dict()
@ -94,18 +92,17 @@ class Simulator:
if node_key not in sharing: if node_key not in sharing:
sharing[node_key] = "" sharing[node_key] = ""
sharing[node_key]+=str(int(self.sharing[interface][node.node_id])) sharing[node_key]+=str(int(self.sharing[interface][node.node_id]))
print("Node number per state: ",end="") debug_file.write("Node number per state: ")
for key in states: for key in states:
print(key+"="+str(states[key]), end=" ") debug_file.write(key+"="+str(states[key]))
print("\nNode sharing: ",end="") debug_file.write("\nNode sharing: ")
for node_id in sharing: for node_id in sharing:
print(node_id+"="+sharing[node_id], end=" ") debug_file.write(node_id+"="+sharing[node_id])
print("\nIds of node in timeout mode: ", end="") debug_file.write("\nIds of node in timeout mode: ")
for n in timeout_mode: for n in timeout_mode:
print(n,end=" ") debug_file.write(n)
print("\nSorted events list:") debug_file.write("\nSorted events list:\n")
print(self.events) debug_file.write(np.array_str(self.events)+"\n")
sys.stdout = stdout_save
def create_node(self, src, args=None): def create_node(self, src, args=None):
""" """