Refactor logging setup across multiple modules to use loguru with consistent configuration

- Updated logging initialization in MessageCalendar, admin_edit_prof, elsa_main, graph, iconLine, searchPage, and richtext modules to use loguru.
- Changed log rotation and retention settings for log files to improve log management.
- Replaced logger.debug/info calls with log.debug/info for consistency.
- Fixed a typo in the searchPage UI and updated related references in the UI files.
- Removed unused imports and cleaned up code for better readability.
This commit is contained in:
2025-05-13 15:49:52 +02:00
parent 4a3a95623a
commit f7c499ea6e
32 changed files with 412 additions and 491 deletions

View File

@@ -9,15 +9,14 @@ from src.logic import elsa_word_to_csv, Prof
from src.ui.dialogs import ElsaAddEntry, popus_confirm
from src.ui.widgets import FilePicker, DataGraph
from src.backend import recreateElsaFile
import loguru
import sys
from loguru import logger as log
log = loguru.logger
log.remove()
log.add(sys.stdout)
log.add("logs/application.log", rotation="1 MB", retention="10 days")
logger = log
logger.remove()
logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True)
log.add("logs/elsa_main.log", enqueue=True)
logger.add(sys.stdout)
class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
@@ -93,7 +92,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
self.newProf_title.textChanged.connect(self.checkProfData)
self.loadFrame()
logger.info("Elsa Dialog loaded")
log.info("Elsa Dialog loaded")
# self.show()
def checkProfData(self):
@@ -237,7 +236,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
fullname=f"{prof.split(', ')[0]} {prof.split(', ')[1]}",
)
prof_id = self.db.getProfId(profdata)
logger.debug(f"ProfData: {profdata}, id:{prof_id}")
log.debug(f"ProfData: {profdata}, id:{prof_id}")
if prof_id is None:
self.db.createProf(profdata)
@@ -263,12 +262,12 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
files,
elsa_id,
)
logger.info("Stored {} files in the database", len(files))
log.info("Stored {} files in the database", len(files))
self.cancel_elsa_creation()
self.refresh_elsa_table()
self.elsa_prof.setCurrentText("")
self.quote_entry.setEnabled(False)
logger.info("Saved apparat to database, id {}", elsa_id)
log.info("Saved apparat to database, id {}", elsa_id)
def refresh_elsa_table(self):
self.elsa_table.setRowCount(0)
@@ -288,13 +287,13 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
def open_elsa(self):
prof = self.elsa_table.item(self.elsa_table.currentRow(), 0).text()
logger.info("prof", prof)
log.info("prof", prof)
date = self.elsa_table.item(self.elsa_table.currentRow(), 1).text()
semester = self.elsa_table.item(self.elsa_table.currentRow(), 2).text()
self.elsa_update.setEnabled(True)
self.elsa_save.setEnabled(False)
if self.elsa_prof.currentText() == prof and date == self.elsa_date.text():
logger.debug("Same prof, stopping")
log.debug("Same prof, stopping")
return
self.create_frame_elsa.setEnabled(True)
self.dokument_list_elsa.setRowCount(0)
@@ -314,7 +313,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
self.elsa_date.setText(date)
self.elsa_semester.setText(semester)
self.elsa_prof.setCurrentText(prof)
logger.info("Elsa ID is {}", elsa_id)
log.info("Elsa ID is {}", elsa_id)
if elsa_id is None:
return
documents = self.db.getElsaFiles(elsa_id)
@@ -411,7 +410,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
self.elsa_semester.text(),
self.elsa_date.text(),
)
logger.debug(
log.debug(
f"elsa_id: {elsa_id}, prof: {self.elsa_prof.currentText()}, semester: {self.elsa_semester.text()}, date: {self.elsa_date.text()}"
)
for row in data:
@@ -445,7 +444,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
try:
self.elsa_statistics.removeTab(1)
except:
logger.debug("No tab to remove")
log.debug("No tab to remove")
self.elsa_table.setRowCount(0)
elsa_apparats = self.db.getElsaApparats()
# elsa_apparats = natsorted(elsa_apparats, key=lambda x: x[2], reverse=True)
@@ -469,7 +468,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
data=self.graph_data,
label="Anzahl der Apparate",
)
logger.debug(self.graph_data)
log.debug(self.graph_data)
self.elsa_statistics_table.setRowCount(0)
for i in range(len(self.graph_data["x"])):
self.elsa_statistics_table.insertRow(0)
@@ -483,7 +482,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
def launch():
logger.debug("Launching Elsa Dialog")
log.debug("Launching Elsa Dialog")
app = QtWidgets.QApplication([])
window = ElsaDialog()
window.show()