Compare commits

..

No commits in common. "716ec42b486cb3713d97f8165a46338085a68ec5" and "4d937f14b32480570c9f4d97793c2806fb2667e1" have entirely different histories.

5 changed files with 24 additions and 32 deletions

3
.gitmodules vendored
View File

@ -1,6 +1,3 @@
[submodule "report"]
path = report
url = https://git.mount-mockery.de/pylib/report.git
[submodule "mytui"]
path = mytui
url = https://git.mount-mockery.de/pylib/mytui.git

2
loggy
View File

@ -2,5 +2,5 @@
#
BASEPATH=$(dirname $0)
$BASEPATH/venv/bin/python $BASEPATH/loggy.py $*
$BASEPATH/venv/bin/python $BASEPATH/loggy.py

View File

@ -1,6 +1,5 @@
import logging
import pickle
import re
import socket
import struct
import threading
@ -8,9 +7,7 @@ from datetime import datetime
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import Footer, Header, Input, RichLog, Checkbox, Select
from mytui import MultiSelect
from textual.widgets import Footer, Header, Input, RichLog, Checkbox
# Mapping von Log-Level-Namen zu Farben für die Anzeige
LEVEL_STYLES = {
@ -66,14 +63,13 @@ class LogViewerApp(App):
("q", "quit", "Quit"),
("c", "clear_screen", "Clear")
]
MAX_LOGS = 1000
def __init__(self):
super().__init__()
#
self.all_logs = []
self.__module_selection__ = MultiSelect((), prompt="Module", id="module_filter")
self.__level_selection__ = MultiSelect((), prompt="Level", id="level_filter")
self.module_filter = ""
self.level_filter = ""
self.force_critical = True
self.force_error = True
self.force_warning = False
@ -85,9 +81,8 @@ class LogViewerApp(App):
with Vertical(id="app-grid"):
yield self.log_display
with Vertical(id="bottom-bar"):
yield self.__module_selection__
yield Input(placeholder="Filter", id="select_filter")
yield self.__level_selection__
yield Input(placeholder="module filter...", id="module_filter")
yield Input(placeholder="level filter...", id="level_filter")
yield Checkbox("CRITICAL", self.force_critical, id="force_critical")
yield Checkbox("ERROR", self.force_error, id="force_error")
yield Checkbox("WARNING", self.force_warning, id="force_warning")
@ -100,11 +95,7 @@ class LogViewerApp(App):
def add_log(self, record: logging.LogRecord) -> None:
"""Fügt einen neuen Log-Eintrag hinzu und aktualisiert die Anzeige."""
self.__module_selection__.AddEntry(record.name)
self.__level_selection__.AddEntry(record.levelname)
self.all_logs.append(record)
if len(self.all_logs) > self.MAX_LOGS:
self.all_logs = self.all_logs[-self.MAX_LOGS:]
self._apply_filters_to_log(record)
def _force(self, lvl: str) -> bool:
@ -116,8 +107,13 @@ class LogViewerApp(App):
def _apply_filters_to_log(self, record: logging.LogRecord):
"""Prüft einen einzelnen Log-Eintrag gegen die Filter und zeigt ihn ggf. an."""
module_match = self.__module_selection__.IsSelected(record.name)
level_match = self.__level_selection__.IsSelected(record.levelname)
module_match = False
for module_filter in self.module_filter.split(","):
module_match |= module_filter.lower() in record.name.lower()
level_match = False
for level_filter in self.level_filter.split(","):
level_match |= level_filter.lower() in record.levelname.lower()
if self._force(record.levelname.lower()) or (module_match and level_match):
level_style = LEVEL_STYLES.get(record.levelname, "white")
@ -144,6 +140,15 @@ class LogViewerApp(App):
for record in self.all_logs:
self._apply_filters_to_log(record)
def on_input_changed(self, message: Input.Changed) -> None:
"""Aktualisiert die Filter und die Anzeige, wenn der Benutzer tippt."""
if message.input.id == "module_filter":
self.module_filter = message.value
elif message.input.id == "level_filter":
self.level_filter = message.value
self._update_display()
def on_checkbox_changed(self, message: Checkbox.Changed) -> None:
if message.checkbox.id == "force_critical":
self.force_critical = message.value
@ -154,15 +159,6 @@ class LogViewerApp(App):
self._update_display()
def on_input_changed(self, message: Input.Changed) -> None:
"""Update the tui inputs and execute task, if requireed."""
if message.input.id == "select_filter":
self.__module_selection__.SetSelectionRegEx(message.value)
def on_select_changed(self, message: Select.Changed) -> None:
if message.select.id in ('module_filter', 'level_filter'):
self._update_display()
if __name__ == "__main__":
app = LogViewerApp()

1
mytui

@ -1 +0,0 @@
Subproject commit bd390d27f00147c1305e244fbd6d0650a6bdcec9

View File

@ -7,8 +7,8 @@
#bottom-bar {
layout: grid;
grid-size: 6;
grid-columns: 4fr 1fr 2fr 15 15 15;
grid-size: 5;
grid-columns: 1fr 1fr 15 15 15;
height: 4;
border-top: solid $primary;
}