read highlighters from settings.ini

This commit is contained in:
2021-10-29 11:53:47 +02:00
parent 5b9db22f39
commit d4db320e17
3 changed files with 69 additions and 10 deletions

View File

@@ -15,8 +15,8 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
2019-08-07 00:02:10,598 [catalina-exec-16] INFO c.r.c.u.l.PerformancePointcut - Executed SecurityController.loginIndex in 0 ms successful. [jv3fw7r2.m1uf] 2019-08-07 00:02:10,598 [catalina-exec-16] INFO c.r.c.u.l.PerformancePointcut - Executed SecurityController.loginIndex in 0 ms successful. [jv3fw7r2.m1uf]
2019-08-07 00:02:16,467 [catalina-exec-36] INFO c.r.c.u.l.PerformancePointcut - Executed HealthCheckController.checkOperativeness in 1 ms successful. [jv3fw7r2.m1ug] 2019-08-07 00:02:16,467 [catalina-exec-36] INFO c.r.c.u.l.PerformancePointcut - Executed HealthCheckController.checkOperativeness in 1 ms successful. [jv3fw7r2.m1ug]
2019-08-07 00:02:23,519 [catalina-exec-53] ERROR c.r.c.u.l.PerformancePointcut - Executed AuthenticationProvider.authenticate in 224 ms successful. [jv3fw7r2.m1uh] 2019-08-07 00:02:23,519 [catalina-exec-53] ERROR c.r.c.u.l.PerformancePointcut - Executed AuthenticationProvider.authenticate in 224 ms successful. [jv3fw7r2.m1uh]
2019-08-07 00:02:24,195 [catalina-exec-43] INFO c.r.c.u.l.PerformancePointcut - Executed SecurityController.accessDenied in 0 ms successful. [jv3fw7r2.m1uj] 2019-08-07 00:02:24,195 [catalina-exec-43] WARN c.r.c.u.l.PerformancePointcut - Executed SecurityController.accessDenied in 0 ms successful. [jv3fw7r2.m1uj]
2019-08-07 00:02:24,937 [catalina-exec-74] INFO c.r.c.u.l.PerformancePointcut - Executed RedirectController.redirect in 1159 ms successful. [jv3fw7r2.m1ui] 2019-08-07 00:02:24,937 [catalina-exec-74] WARN c.r.c.u.l.PerformancePointcut - Executed RedirectController.redirect in 1159 ms successful. [jv3fw7r2.m1ui]
2019-08-07 00:02:25,674 [catalina-exec-29] INFO c.r.c.u.l.PerformancePointcut - Executed AssignmentsController.index in 683 ms successful. [jv3fw7r2.m1uk] 2019-08-07 00:02:25,674 [catalina-exec-29] INFO c.r.c.u.l.PerformancePointcut - Executed AssignmentsController.index in 683 ms successful. [jv3fw7r2.m1uk]
2019-08-07 00:02:26,825 [catalina-exec-20] INFO c.r.c.u.l.PerformancePointcut - Executed I18NController.getI18NKeyValues in 1 ms successful. [jv3fw7r2.m1ul] 2019-08-07 00:02:26,825 [catalina-exec-20] INFO c.r.c.u.l.PerformancePointcut - Executed I18NController.getI18NKeyValues in 1 ms successful. [jv3fw7r2.m1ul]
2018-09-06T00:00:16.381Z,0,vapfacbk01,HealthCheckService.isOperable,AXC_5.14_526,,successful 2018-09-06T00:00:16.381Z,0,vapfacbk01,HealthCheckService.isOperable,AXC_5.14_526,,successful

57
highlighting.py Normal file
View File

@@ -0,0 +1,57 @@
import logging
import re
from PyQt6.QtGui import QBrush, QColor
from highlight import Highlight
from highlight_regex import HighlightRegex
from settings import Settings
log = logging.getLogger("highlighting")
class Highlighting:
@staticmethod
def read_config(settings: Settings) -> [Highlight]:
result = []
config = settings.config
for section in config.sections():
if not section.startswith("highlighting."):
continue
query = config.get(section, "query", fallback="")
if len(query) == 0:
continue
ignore_case = config.getboolean(section, "ignore-case", fallback=True)
is_regex = config.getboolean(section, "is-regex", fallback=False)
line_background_color = Highlighting.brush(config.get(section, "line.background.color", fallback="None"))
hit_background_color = Highlighting.brush(config.get(section, "hit.background.color", fallback="None"))
try:
flags = re.IGNORECASE if ignore_case else 0
if is_regex:
regex = re.compile(query, flags=flags)
else:
regex = re.compile(re.escape(query), flags=flags)
except:
log.exception("failed to parse query for highlighter: %s" % section)
continue
highlight = HighlightRegex(
regex=regex,
brush=hit_background_color,
brush_full_line=line_background_color
)
result.append(highlight)
return result
@staticmethod
def brush(color: str) -> QBrush:
if re.match("[0-9a-f]{6}", color, flags=re.IGNORECASE):
red = int(color[0:2], 16)
green = int(color[2:4], 16)
blue = int(color[4:6], 16)
return QBrush(QColor(red, green, blue))
return QBrush()

View File

@@ -7,6 +7,7 @@ from typing import List, Optional
from PyQt6.QtGui import QBrush, QColor, QPen from PyQt6.QtGui import QBrush, QColor, QPen
from highlight_regex import HighlightRegex from highlight_regex import HighlightRegex
from highlighting import Highlighting
from line import Line from line import Line
import os import os
from settings import Settings from settings import Settings
@@ -20,14 +21,15 @@ class LogFileModel:
self._file = os.path.realpath(file) self._file = os.path.realpath(file)
self._lock = threading.RLock() self._lock = threading.RLock()
self.highlights = [ self.highlights = Highlighting.read_config(settings)
HighlightRegex( # [
re.compile("ERROR"), # HighlightRegex(
brush=QBrush(QColor(220, 112, 122)), # re.compile("ERROR"),
pen=QPen(QColor(0, 0, 0)), # brush=QBrush(QColor(220, 112, 122)),
brush_full_line=QBrush(QColor(255, 112, 122)) # pen=QPen(QColor(0, 0, 0)),
) # brush_full_line=QBrush(QColor(255, 112, 122))
] # )
# ]
def get_file(self): def get_file(self):
return self._file return self._file