mirror of
https://github.com/nod-ai/SHARK-Studio.git
synced 2026-01-08 05:24:00 -05:00
38 lines
805 B
Python
38 lines
805 B
Python
import sys
|
|
|
|
|
|
class Logger:
|
|
def __init__(self, filename, filter=None):
|
|
self.terminal = sys.stdout
|
|
self.log = open(filename, "w")
|
|
self.filter = filter
|
|
|
|
def write(self, message):
|
|
for x in message.split("\n"):
|
|
if self.filter in x:
|
|
self.log.write(message)
|
|
else:
|
|
self.terminal.write(message)
|
|
|
|
def flush(self):
|
|
self.terminal.flush()
|
|
self.log.flush()
|
|
|
|
def isatty(self):
|
|
return False
|
|
|
|
|
|
def logger_test(x):
|
|
print("[LOG] This is a test")
|
|
print(f"This is another test, without the filter")
|
|
return x
|
|
|
|
|
|
def read_sd_logs():
|
|
sys.stdout.flush()
|
|
with open("amdshark_tmp/sd.log", "r") as f:
|
|
return f.read()
|
|
|
|
|
|
sys.stdout = Logger("amdshark_tmp/sd.log", filter="[LOG]")
|