Add debug log level

This commit is contained in:
George Lacey 2025-01-18 18:50:10 +00:00
parent 860417488f
commit 965197cd6a
3 changed files with 19 additions and 8 deletions

View File

@ -1,6 +1,7 @@
INFO=0 DEBUG=0
WARNING=5 INFO=5
ERROR=10 WARNING=10
ERROR=20
from .log import Log from .log import Log
from .logcat import LogCat from .logcat import LogCat

View File

@ -2,11 +2,11 @@ from datetime import datetime
from multiprocessing import Lock from multiprocessing import Lock
from threading import Thread from threading import Thread
from queue import Queue, Empty from queue import Queue, Empty
from . import INFO, WARNING, ERROR from . import DEBUG, INFO, WARNING, ERROR
class Log(object): 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.__terminated = False
self.level = level self.level = level
self.file_lock = Lock() self.file_lock = Lock()
@ -78,4 +78,9 @@ class Log(object):
self.set_log_file() self.set_log_file()
with self.file_lock: with self.file_lock:
with open(self.log_file, mode='a') as log_file: 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)

View File

@ -1,6 +1,6 @@
from datetime import datetime from datetime import datetime
from multiprocessing import Queue from multiprocessing import Queue
from . import INFO, WARNING, ERROR from . import DEBUG, INFO, WARNING, ERROR
class LogCat(object): class LogCat(object):
@ -13,6 +13,9 @@ class LogCat(object):
time = datetime.now().strftime("%Y-%m-%dT%H:%M:%S") 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}")) 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: def info(self, function: str, message: str) -> None:
self._write(INFO, function, message) self._write(INFO, function, message)
@ -24,7 +27,9 @@ class LogCat(object):
@staticmethod @staticmethod
def level_string(level: int) -> str: def level_string(level: int) -> str:
if level == INFO: if level == DEBUG:
return "DEBG"
elif level == INFO:
return "INFO" return "INFO"
elif level == WARNING: elif level == WARNING:
return "WARN" return "WARN"