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:
@@ -1,32 +1,31 @@
|
||||
__all__ = [
|
||||
"add_bookdata_ui",
|
||||
"edit_bookdata_ui",
|
||||
"login_ui",
|
||||
"BookDataUI",
|
||||
"LoginDialog",
|
||||
"Mail_Dialog",
|
||||
"MailTemplateDialog",
|
||||
"medienadder_ui",
|
||||
"parsed_titles_ui",
|
||||
"MedienAdder",
|
||||
"ParsedTitles",
|
||||
"popus_confirm",
|
||||
"reminder_ui",
|
||||
"Settings",
|
||||
"ReminderDialog",
|
||||
"About",
|
||||
"ElsaGenConfirm",
|
||||
"ElsaAddEntry",
|
||||
"ApparatExtendDialog",
|
||||
"DocumentPrintDialog",
|
||||
"Settings",
|
||||
]
|
||||
from .bookdata import BookDataUI as edit_bookdata_ui
|
||||
from .login import LoginDialog as login_ui
|
||||
from .bookdata import BookDataUI
|
||||
from .login import LoginDialog
|
||||
from .mail import Mail_Dialog
|
||||
from .mailTemplate import MailTemplateDialog
|
||||
from .medienadder import MedienAdder as medienadder_ui
|
||||
from .parsed_titles import ParsedTitles as parsed_titles_ui
|
||||
from .medienadder import MedienAdder
|
||||
from .parsed_titles import ParsedTitles
|
||||
from .popup_confirm import ConfirmDialog as popus_confirm
|
||||
from .reminder import ReminderDialog as reminder_ui
|
||||
from .reminder import ReminderDialog
|
||||
from .about import About
|
||||
from .elsa_gen_confirm import ElsaGenConfirm
|
||||
from .elsa_add_entry import ElsaAddEntry
|
||||
from .app_ext import ApparatExtendDialog
|
||||
from .docuprint import DocumentPrintDialog, launch
|
||||
from .docuprint import DocumentPrintDialog
|
||||
|
||||
from .settings import Settings
|
||||
|
||||
@@ -118,7 +118,7 @@ class ElsaAddEntry(QtWidgets.QDialog, Ui_Dialog):
|
||||
if table["type"] == "zs":
|
||||
book = zot.createBook(table["isbn"])
|
||||
res_key = zot.createJournalArticle(book, table)
|
||||
logger.debug(book)
|
||||
log.debug(book)
|
||||
a_lastname = table["section_author"].split(";")[0].strip().split(",")[0]
|
||||
a_firstname = table["section_author"].split(";")[0].strip().split(",")[1]
|
||||
author = f"{a_lastname}, {a_firstname[0]}"
|
||||
|
||||
@@ -6,18 +6,15 @@ from PyQt6 import QtCore, QtWidgets
|
||||
from src.backend.admin_console import AdminCommands
|
||||
from src.backend.database import Database
|
||||
|
||||
from .dialog_sources.Ui_login import Ui_Dialog
|
||||
from .dialog_sources.login_ui import Ui_Dialog
|
||||
import sys
|
||||
from loguru import logger as log
|
||||
import loguru
|
||||
from src import Icon
|
||||
|
||||
logger = log
|
||||
logger.remove()
|
||||
logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True)
|
||||
|
||||
|
||||
# logger.add(sys.stderr, format="{time} {level} {message}", level="INFO")
|
||||
logger.add(sys.stdout)
|
||||
log = loguru.logger
|
||||
log.remove()
|
||||
log.add(sys.stdout)
|
||||
log.add("logs/application.log", rotation="1 MB", retention="10 days")
|
||||
|
||||
|
||||
class LoginDialog(Ui_Dialog):
|
||||
@@ -86,7 +83,7 @@ class LoginDialog(Ui_Dialog):
|
||||
if self.db.login(username, hashed_password):
|
||||
self.lresult = 1 # Indicate successful login
|
||||
self.lusername = username
|
||||
logger.success(f"User {username} logged in.")
|
||||
log.success(f"User {username} logged in.")
|
||||
self.dialog.accept()
|
||||
|
||||
else:
|
||||
|
||||
@@ -8,21 +8,14 @@ from src import Icon, settings as config
|
||||
|
||||
from .dialog_sources.Ui_mail_preview import Ui_eMailPreview as MailPreviewDialog
|
||||
from .mailTemplate import MailTemplateDialog
|
||||
import loguru
|
||||
import sys
|
||||
from loguru import logger as log
|
||||
|
||||
logger = log
|
||||
logger.remove()
|
||||
logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True)
|
||||
log.add(
|
||||
"logs/mail.log",
|
||||
rotation="1 day",
|
||||
compression="zip",
|
||||
enqueue=True,
|
||||
)
|
||||
log = loguru.logger
|
||||
log.remove()
|
||||
log.add(sys.stdout)
|
||||
log.add("logs/application.log", rotation="1 MB", retention="10 days")
|
||||
|
||||
# logger.add(sys.stderr, format="{time} {level} {message}", level="INFO")
|
||||
logger.add(sys.stdout)
|
||||
|
||||
|
||||
empty_signature = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
@@ -60,7 +53,7 @@ class Mail_Dialog(QtWidgets.QDialog, MailPreviewDialog):
|
||||
super().__init__(parent)
|
||||
self.setupUi(self)
|
||||
|
||||
logger.info("Setting up mail dialog")
|
||||
log.info("Setting up mail dialog")
|
||||
self.appid = app_id
|
||||
self.appname = app_name
|
||||
self.subject = app_subject
|
||||
@@ -92,7 +85,7 @@ class Mail_Dialog(QtWidgets.QDialog, MailPreviewDialog):
|
||||
self.btn_okay.clicked.connect(self.createAndSendMail)
|
||||
|
||||
def open_new_template(self):
|
||||
logger.info("Opening new template dialog")
|
||||
log.info("Opening new template dialog")
|
||||
# TODO: implement new mail template dialog
|
||||
dialog = MailTemplateDialog()
|
||||
dialog.updateSignal.connect(self.load_mail_templates)
|
||||
@@ -111,9 +104,9 @@ Tel.: 0761/682-778 | 07617682-545"""
|
||||
|
||||
def load_mail_templates(self):
|
||||
# print("loading mail templates")
|
||||
logger.info("Loading mail templates")
|
||||
log.info("Loading mail templates")
|
||||
mail_templates = os.listdir("mail_vorlagen")
|
||||
logger.info(f"Mail templates: {mail_templates}")
|
||||
log.info(f"Mail templates: {mail_templates}")
|
||||
self.comboBox.clear()
|
||||
for template in mail_templates:
|
||||
self.comboBox.addItem(template)
|
||||
@@ -132,10 +125,10 @@ Tel.: 0761/682-778 | 07617682-545"""
|
||||
return f"Guten Tag {name},"
|
||||
|
||||
def set_mail(self):
|
||||
logger.info("Setting mail")
|
||||
log.info("Setting mail")
|
||||
email_template = self.comboBox.currentText()
|
||||
if email_template == "":
|
||||
logger.debug("No mail template selected")
|
||||
log.debug("No mail template selected")
|
||||
return
|
||||
with open(f"mail_vorlagen/{email_template}", "r", encoding="utf-8") as f:
|
||||
mail_template = f.read()
|
||||
@@ -160,7 +153,7 @@ Tel.: 0761/682-778 | 07617682-545"""
|
||||
self.mail_body.setHtml(mail_html)
|
||||
|
||||
def createAndSendMail(self):
|
||||
logger.info("Sending mail")
|
||||
log.info("Sending mail")
|
||||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
@@ -197,7 +190,7 @@ Tel.: 0761/682-778 | 07617682-545"""
|
||||
# print("Mail sent")
|
||||
# end active process
|
||||
server.quit()
|
||||
logger.info("Mail sent, closing connection to server and dialog")
|
||||
log.info("Mail sent, closing connection to server and dialog")
|
||||
# close the dialog
|
||||
|
||||
self.accept()
|
||||
|
||||
@@ -52,7 +52,7 @@ class MailTemplateDialog(QtWidgets.QDialog, NewMailTemplateDesignerDialog):
|
||||
self.buttonBox.button(
|
||||
QtWidgets.QDialogButtonBox.StandardButton.Cancel
|
||||
).clicked.connect(self.closeNow)
|
||||
logger.info("Mail template dialog setup complete")
|
||||
log.info("Mail template dialog setup complete")
|
||||
|
||||
def save_template(self):
|
||||
# print("save triggered")
|
||||
@@ -66,11 +66,11 @@ class MailTemplateDialog(QtWidgets.QDialog, NewMailTemplateDesignerDialog):
|
||||
dialog.setWindowIcon(Icon("save").icon)
|
||||
save = dialog.exec()
|
||||
template_name = dialog.textValue()
|
||||
logger.info("Saving template")
|
||||
log.info("Saving template")
|
||||
if template_name != "" and save == 1:
|
||||
template = template_name + ".eml"
|
||||
if template in os.listdir("mail_vorlagen"):
|
||||
logger.error("Template already exists")
|
||||
log.error("Template already exists")
|
||||
# warning dialog
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
dialog.setIcon(QtWidgets.QMessageBox.Icon.Warning)
|
||||
@@ -110,7 +110,7 @@ Content-Transfer-Encoding: 8bit
|
||||
f.write(mail)
|
||||
self.updateSignal.emit()
|
||||
self.close()
|
||||
logger.success(f"Template {template} saved successfully")
|
||||
log.success(f"Template {template} saved successfully")
|
||||
else:
|
||||
# warning dialog
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from .dialog_sources.Ui_medianadder import Ui_Dialog
|
||||
from .dialog_sources.medianadder_ui import Ui_Dialog
|
||||
from src import Icon
|
||||
|
||||
|
||||
|
||||
@@ -3,15 +3,14 @@ from PyQt6 import QtWidgets
|
||||
from src.backend import AutoAdder
|
||||
|
||||
|
||||
from .dialog_sources.Ui_parsed_titles import Ui_Form
|
||||
from .dialog_sources.parsed_titles_ui import Ui_Form
|
||||
import loguru
|
||||
import sys
|
||||
|
||||
log = loguru.logger
|
||||
log.remove()
|
||||
log.add("application.log", rotation="1 week", retention="1 month")
|
||||
log.add(sys.stdout, level="INFO")
|
||||
|
||||
log.add(sys.stdout)
|
||||
log.add("logs/application.log", rotation="1 MB", retention="10 days")
|
||||
|
||||
class ParsedTitles(QtWidgets.QWidget, Ui_Form):
|
||||
def __init__(self, parent=None):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from PyQt6 import QtWidgets
|
||||
|
||||
from .dialog_sources.Ui_reminder import Ui_Erinnerung as Ui_Dialog
|
||||
from .dialog_sources.reminder_ui import Ui_Erinnerung as Ui_Dialog
|
||||
from src import Icon
|
||||
import datetime as date
|
||||
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
from src import Icon, settings
|
||||
from .dialog_sources.Ui_settings import Ui_Dialog as _settings
|
||||
from .dialog_sources.settings_ui import Ui_Dialog as _settings
|
||||
from src.ui.widgets.iconLine import IconWidget
|
||||
import loguru
|
||||
import sys
|
||||
from loguru import logger as log
|
||||
|
||||
logger = log
|
||||
logger.remove()
|
||||
logger.add("logs/application.log", rotation="1 week", retention="1 month", enqueue=True)
|
||||
log.add(
|
||||
f"logs/settings.log",
|
||||
)
|
||||
log = loguru.logger
|
||||
log.remove()
|
||||
log.add(sys.stdout)
|
||||
log.add("logs/application.log", rotation="1 MB", retention="10 days")
|
||||
|
||||
# logger.add(sys.stderr, format="{time} {level} {message}", level="INFO")
|
||||
logger.add(sys.stdout)
|
||||
|
||||
|
||||
base = """'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
@@ -80,7 +76,7 @@ class Settings(QtWidgets.QDialog, _settings):
|
||||
self.toolBox.setItemIcon(2, Icon("mail").icon)
|
||||
self.toolBox.setItemIcon(3, Icon("icons").icon)
|
||||
|
||||
logger.info("Settings dialog opened, data loaded")
|
||||
log.info("Settings dialog opened, data loaded")
|
||||
|
||||
def load_config(self):
|
||||
self.db_name.setText(settings.database.name)
|
||||
@@ -117,7 +113,7 @@ class Settings(QtWidgets.QDialog, _settings):
|
||||
self.vertical_icons.addWidget(icon_widget)
|
||||
|
||||
def change_color(self, lineedit):
|
||||
logger.debug("Changing color for {}", lineedit.text())
|
||||
log.debug("Changing color for {}", lineedit.text())
|
||||
colorDialog = QtWidgets.QColorDialog()
|
||||
colorDialog.setSizePolicy()
|
||||
color = colorDialog.getColor()
|
||||
@@ -191,7 +187,7 @@ class Settings(QtWidgets.QDialog, _settings):
|
||||
self.save_path.setText(file_dialog.selectedFiles()[0])
|
||||
|
||||
def debug_mode(self):
|
||||
logger.debug(self.editSignature.toHtml())
|
||||
log.debug(self.editSignature.toHtml())
|
||||
|
||||
def return_data(self):
|
||||
port = self.smtp_port.text()
|
||||
|
||||
Reference in New Issue
Block a user