mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
log
This commit is contained in:
parent
3a4489e0eb
commit
54ab639e23
@ -1,4 +1,4 @@
|
|||||||
import sys, os, io, time, threading
|
import sys, os, io, time, threading, queue
|
||||||
|
|
||||||
|
|
||||||
def prepareqtenv():
|
def prepareqtenv():
|
||||||
@ -170,45 +170,39 @@ def switchdir():
|
|||||||
|
|
||||||
class Lockedfile:
|
class Lockedfile:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.file = None
|
self.collect = queue.Queue()
|
||||||
self.lock = threading.Lock()
|
threading.Thread(target=self.__write).start()
|
||||||
|
|
||||||
|
def __write(self):
|
||||||
|
data = self.collect.get()
|
||||||
|
file = open(
|
||||||
|
f"logs/{time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())}.txt",
|
||||||
|
"w",
|
||||||
|
errors="ignore",
|
||||||
|
)
|
||||||
|
while True:
|
||||||
|
file.write(data)
|
||||||
|
file.flush()
|
||||||
|
data = self.collect.get()
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
try:
|
self.collect.put(data)
|
||||||
self._write(data)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _write(self, data):
|
|
||||||
with self.lock:
|
|
||||||
if self.file is None:
|
|
||||||
self.file = open(
|
|
||||||
f"logs/{time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())}.txt",
|
|
||||||
"w",
|
|
||||||
errors="ignore",
|
|
||||||
)
|
|
||||||
self.file.write(data)
|
|
||||||
self.file.flush()
|
|
||||||
|
|
||||||
|
|
||||||
lockedfile = Lockedfile()
|
lockedfile = Lockedfile()
|
||||||
|
|
||||||
|
|
||||||
class debugoutput(io.IOBase):
|
class debugoutput(io.IOBase):
|
||||||
file = None
|
def __init__(self, file: io.TextIOBase) -> None:
|
||||||
|
|
||||||
def __init__(self, file=sys.stdout) -> None:
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.originfile = file
|
self.originfile = file
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
if self.originfile:
|
self.originfile.write(data)
|
||||||
self.originfile.write(data)
|
|
||||||
lockedfile.write(data)
|
lockedfile.write(data)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
if self.originfile:
|
self.originfile.flush()
|
||||||
self.originfile.flush()
|
|
||||||
|
|
||||||
|
|
||||||
def savelogs():
|
def savelogs():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user