Skip to content

Commit

Permalink
html: Show messages in monospace/preformatted
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakuje committed Sep 13, 2024
1 parent b850879 commit d59c5a2
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions SCAutolib/models/gui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
import inspect
import os
from os.path import join
Expand All @@ -15,28 +14,6 @@
from SCAutolib.isDistro import isDistro


class HTMLFileHandler(logging.FileHandler):
"""Extending FileHandler to work with HTML files."""

def __init__(
self, filename, mode='a', encoding=None, delay=False, errors=None):
"""
A handler class which writes formatted logging records to disk HTML
files.
"""
super(HTMLFileHandler, self).__init__(
filename, mode, encoding, delay, errors
)

def emit(self, record: logging.LogRecord) -> None:
"""
Do whatever it takes to actually log the specified logging record.
"""
custom_record = copy.deepcopy(record)
custom_record.msg = str(record.msg).rstrip().replace("\n", "<br>\n")
return super().emit(custom_record)


class Screen:
"""Captures the screenshots."""

Expand Down Expand Up @@ -292,16 +269,16 @@ def __init__(self, wait_time: float = 5, res_dir_name: str = None):
"initial-scale=1.0\">\n"
"<title>Test Results</title>\n"
"</head>\n"
"<body style=\"background-color:#000\">\n"
"<body style=\"background-color:#000;\">\n"
)

fmt = "<span style=\"color:limegreen;\">"
fmt += "%(asctime)s</span> "
fmt += "<span style=\"color:white;\">"
fmt += "%(name)s:%(module)s.%(funcName)s.%(lineno)d </span>"
fmt += "<span style=\"color:royalblue;\">[%(levelname)s] </span>"
fmt += "<span style=\"color:limegreen;\">%(message)s</span>"
self.fileHandler = HTMLFileHandler(self.html_file)
fmt += "<pre style=\"color:limegreen;\">%(message)s</pre>"
self.fileHandler = logging.FileHandler(self.html_file)
self.fileHandler.setLevel(logging.DEBUG)
self.fileHandler.setFormatter(
logging.Formatter("<p>" + fmt + "</p>")
Expand Down

0 comments on commit d59c5a2

Please sign in to comment.