Add debug log level
This commit is contained in:
parent
860417488f
commit
965197cd6a
|
@ -1,6 +1,7 @@
|
|||
INFO=0
|
||||
WARNING=5
|
||||
ERROR=10
|
||||
DEBUG=0
|
||||
INFO=5
|
||||
WARNING=10
|
||||
ERROR=20
|
||||
|
||||
from .log import Log
|
||||
from .logcat import LogCat
|
||||
|
|
|
@ -2,11 +2,11 @@ from datetime import datetime
|
|||
from multiprocessing import Lock
|
||||
from threading import Thread
|
||||
from queue import Queue, Empty
|
||||
from . import INFO, WARNING, ERROR
|
||||
from . import DEBUG, INFO, WARNING, ERROR
|
||||
|
||||
|
||||
class Log(object):
|
||||
def __init__(self, path, queue=None, print_output=True, timeout=1, level=WARNING):
|
||||
def __init__(self, path, queue=None, print_output=True, timeout=1, level=DEBUG):
|
||||
self.__terminated = False
|
||||
self.level = level
|
||||
self.file_lock = Lock()
|
||||
|
@ -78,4 +78,9 @@ class Log(object):
|
|||
self.set_log_file()
|
||||
with self.file_lock:
|
||||
with open(self.log_file, mode='a') as log_file:
|
||||
log_file.writelines(log_msg_list)
|
||||
for line in log_msg_list:
|
||||
try:
|
||||
log_file.write(line)
|
||||
except Exception as e:
|
||||
print(f"Error writing line{line}")
|
||||
print(e)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from datetime import datetime
|
||||
from multiprocessing import Queue
|
||||
from . import INFO, WARNING, ERROR
|
||||
from . import DEBUG, INFO, WARNING, ERROR
|
||||
|
||||
|
||||
class LogCat(object):
|
||||
|
@ -13,6 +13,9 @@ class LogCat(object):
|
|||
time = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
|
||||
self.queue.put((level, f"{self.level_string(level)} | {time} - {self.category.upper()}.{function.upper()}: {message}"))
|
||||
|
||||
def debug(self, function: str, message: str) -> None:
|
||||
self._write(DEBUG, function, message)
|
||||
|
||||
def info(self, function: str, message: str) -> None:
|
||||
self._write(INFO, function, message)
|
||||
|
||||
|
@ -24,7 +27,9 @@ class LogCat(object):
|
|||
|
||||
@staticmethod
|
||||
def level_string(level: int) -> str:
|
||||
if level == INFO:
|
||||
if level == DEBUG:
|
||||
return "DEBG"
|
||||
elif level == INFO:
|
||||
return "INFO"
|
||||
elif level == WARNING:
|
||||
return "WARN"
|
||||
|
|
Loading…
Reference in New Issue
Block a user