diff --git a/esds/simulator.py b/esds/simulator.py index f2358fc..fee9331 100644 --- a/esds/simulator.py +++ b/esds/simulator.py @@ -76,12 +76,10 @@ class Simulator: """ Log all the informations for debugging """ - stdout_save = sys.stdout with open(self.debug_file_path, "a") as debug_file: - sys.stdout = debug_file - print("-----------------------------------------------") - print("Started since {}s".format(round(time.time()-self.startat,2))) - print("Simulated time {}s (or more precisely {}s)".format(self.time_truncated,self.time)) + debug_file.write("-----------------------------------------------\n") + debug_file.write("Started since {}s\n".format(round(time.time()-self.startat,2))) + debug_file.write("Simulated time {}s (or more precisely {}s)\n".format(self.time_truncated,self.time)) states=dict() timeout_mode=list() sharing=dict() @@ -94,18 +92,17 @@ class Simulator: if node_key not in sharing: sharing[node_key] = "" 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: - print(key+"="+str(states[key]), end=" ") - print("\nNode sharing: ",end="") + debug_file.write(key+"="+str(states[key])) + debug_file.write("\nNode sharing: ") for node_id in sharing: - print(node_id+"="+sharing[node_id], end=" ") - print("\nIds of node in timeout mode: ", end="") + debug_file.write(node_id+"="+sharing[node_id]) + debug_file.write("\nIds of node in timeout mode: ") for n in timeout_mode: - print(n,end=" ") - print("\nSorted events list:") - print(self.events) - sys.stdout = stdout_save + debug_file.write(n) + debug_file.write("\nSorted events list:\n") + debug_file.write(np.array_str(self.events)+"\n") def create_node(self, src, args=None): """