mirror of
https://github.com/dobin/SuperMega
synced 2026-06-02 17:27:10 +00:00
refactor: consolidate all three log things (cmd output, logger, files) into observer
This commit is contained in:
+14
@@ -9,17 +9,31 @@ from model.defs import *
|
||||
|
||||
class Observer():
|
||||
def __init__(self):
|
||||
self.cmd_output = []
|
||||
self.logs = []
|
||||
self.idx = 0
|
||||
self.active = True
|
||||
|
||||
def reset(self):
|
||||
self.cmd_output = []
|
||||
self.logs = []
|
||||
self.idx = 0
|
||||
|
||||
def add_cmd_output(self, cmd_output):
|
||||
self.cmd_output.append(cmd_output)
|
||||
|
||||
def add_log(self, log):
|
||||
self.logs.append(log)
|
||||
|
||||
def get_logs(self):
|
||||
return self.logs
|
||||
|
||||
def writelog(self):
|
||||
# write log to file
|
||||
with open(f"{logs_dir}/supermega.log", "w") as f:
|
||||
for line in self.logs:
|
||||
f.write(line + "\n")
|
||||
|
||||
def add_text(self, name, data):
|
||||
self.write_to_file(name + ".txt", data)
|
||||
self.idx += 1
|
||||
|
||||
Reference in New Issue
Block a user