-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.py
33 lines (29 loc) · 1.04 KB
/
log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import time
import threading
class Logger():
def __init__(self, log_file:str, vervose:str = False, real = True):
if not real:
return
self.log_file_name = str(log_file)+str(int(time.time()))+".log"
self.queue = []
self.vervose = vervose
self.thread = threading.Thread(target=self.proces_queue)
self.thread.start()
def log(self, *messages):
text = f"[{threading.current_thread().name}]({time.asctime()}) "
for message in messages:
text += str(message) + " "
self.queue.append(text)
def stop(self):
self.queue.append("exit")
def proces_queue(self):
self.queue.append("[STARTED LOGGER]")
while True:
if not len(self.queue) == 0:
if self.queue[0] == "exit":
break
with open(self.log_file_name, "a") as f:
f.write(str(self.queue[0])+"\n")
if self.vervose:
print(self.queue[0])
self.queue.pop(0)