From 84b9de520a1f2d52c259449689725831b189578f Mon Sep 17 00:00:00 2001 From: Nova Date: Sat, 26 Dec 2020 01:09:32 +0530 Subject: [PATCH] #45 Updated html template for displaying logger name --- cvlog/html_logger.py | 15 +++++++++------ cvlog/html_template.py | 6 +++--- cvlog/logger.py | 13 +++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cvlog/html_logger.py b/cvlog/html_logger.py index 43ff020..a21ee55 100644 --- a/cvlog/html_logger.py +++ b/cvlog/html_logger.py @@ -15,24 +15,27 @@ def __init__(self): self.__no_data = False self.__rotate_log() - def log_image(self, level, log_type, img_data, msg): + def log_image(self, level, logger_name, log_type, img_data, msg): data = ''.join(['']) - self.__append_log_item(level, log_type, data, msg) + self.__append_log_item(level, logger_name, log_type, data, msg) - def __append_log_item(self, level, log_type, log_detail, msg): + def __append_log_item(self, level, logger_name, log_type, log_detail, msg): template = '
" - template += '
' + log_type + '
' template += '

' + data['time_stamp'] template += '' + data['level'] + '

' + template += '

' + re.sub(r'^/', '', short_stack) + '

' + template += '
'+ log_type + '
' + template += '
'+ str(logger_name or '') +'
' if msg is not None: template += '

' + msg + '

' - template += '

' + re.sub(r'^/', '', short_stack) + '

' + template+= '' self.__try_append([template]) def __append(self, html_text_seq): @@ -67,7 +70,7 @@ def __create_file(self): if not os.path.exists(dir_path): os.makedirs(dir_path) with open(self.__file_path(), 'w') as html: - html.writelines(['', ht.STYLE, ht.SCRIPT, ht.CONTENT_START, ht.NO_DATA_CONTENT, ht.CONTENT_END]) + html.writelines(['', ht.STYLE, ht.SCRIPT, ht.CONTENT_START, ht.NO_DATA_CONTENT, ht.CONTENT_END]) self.__no_data = True def __rotate_log(self): diff --git a/cvlog/html_template.py b/cvlog/html_template.py index d459bb2..b92ba45 100644 --- a/cvlog/html_template.py +++ b/cvlog/html_template.py @@ -1,5 +1,5 @@ -CONTENT_START = '

Logs

' +CONTENT_START = '

Logs

' CONTENT_END = '
' NO_DATA_CONTENT = '
No data logged
' -SCRIPT = '' -STYLE = '' +SCRIPT = '' +STYLE = '' diff --git a/cvlog/logger.py b/cvlog/logger.py index 31ea38f..56670f8 100644 --- a/cvlog/logger.py +++ b/cvlog/logger.py @@ -8,15 +8,16 @@ class Logger: root = None - def __init__(self): - self.error = BaseLogger(Level.ERROR) - self.info = BaseLogger(Level.INFO) - self.trace = BaseLogger(Level.TRACE) + def __init__(self,name=None): + self.error = BaseLogger(Level.ERROR, name) + self.info = BaseLogger(Level.INFO, name) + self.trace = BaseLogger(Level.TRACE, name) class BaseLogger: root = None - def __init__(self, level=None): + def __init__(self, level=None, name=None): + self.__name=name self.__level = level self.__html_logger = hl.HtmlLogger() @@ -83,7 +84,7 @@ def __log_image(self, level, log_type, img, options): if not retval: return None msg = options.get('msg', None) - self.__html_logger.log_image(level, log_type, base64.b64encode(buffer).decode(), msg) + self.__html_logger.log_image(level, self.__name, log_type, base64.b64encode(buffer).decode(), msg) def show_image(self, title, log_type, img, options): cv2.namedWindow('window', cv2.WINDOW_NORMAL)