Skip to content

Commit

Permalink
enh: limit logs printed to 2000
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 3, 2025
1 parent 38a1480 commit b0b2f71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.16.4
- enh: limit logs printed to 2000
0.16.3
- fix: fall-back to resource size estimation via S3 download header
- tests: fix tests that checked resource size after upload
Expand Down
13 changes: 11 additions & 2 deletions dcoraid/gui/logs/widget_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class WidgetLog(QtWidgets.QWidget):

def __init__(self, *args, **kwargs):
super(WidgetLog, self).__init__(*args, **kwargs)
self.logs_queued_max = 1000
self.logs_printed = 0
self.full_log = deque(maxlen=self.logs_queued_max)

ref_ui = resources.files("dcoraid.gui.logs") / "widget_log.ui"
with resources.as_file(ref_ui) as path_ui:
uic.loadUi(path_ui, self)
Expand Down Expand Up @@ -78,7 +82,6 @@ def __init__(self, *args, **kwargs):
self.on_filter_changed)
self.toolButton_dir.clicked.connect(self.on_log_dir_open)
self.log_handler = StringSignalLogHandler(self.new_message)
self.full_log = deque(maxlen=5000)

@QtCore.pyqtSlot(str)
def add_colored_item(self, msg, append_global=True):
Expand All @@ -102,7 +105,12 @@ def add_colored_item(self, msg, append_global=True):
html_text = f"<div {style}>{html.escape(msg)}</div>"
html_text = html_text.replace("\n", "<br>")

self.textEdit.append(html_text)
self.ui.textEdit.append(html_text)
self.logs_printed += 1

# Clean up every once in a while
if self.logs_printed >= 2 * self.logs_queued_max:
self.on_filter_changed()

def get_level(self, msg):
try:
Expand All @@ -127,6 +135,7 @@ def check_filter(self, msg):
@QtCore.pyqtSlot()
def on_filter_changed(self):
self.textEdit.clear()
self.logs_printed = 0
for msg in self.full_log:
self.add_colored_item(msg, append_global=False)

Expand Down

0 comments on commit b0b2f71

Please sign in to comment.