Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

logger.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import logging
  2. from PyQt5.QtWidgets import QPlainTextEdit, QGroupBox, QVBoxLayout
  3. from ..python_core.appdirs import get_app_log_dir
  4. import pathlib as pl
  5. import time
  6. import sys
  7. # solution copied from https://stackoverflow.com/questions/28655198/best-way-to-display-logs-in-pyqt
  8. class QPlainTextEditLogger(QPlainTextEdit, logging.Handler):
  9. def __init__(self, parent):
  10. super(QPlainTextEdit, self).__init__(parent)
  11. super(logging.Handler, self).__init__()
  12. self.setReadOnly(True)
  13. def emit(self, record):
  14. msg = self.format(record)
  15. text_cursor = self.textCursor()
  16. text_cursor.insertText(f"{msg}\n")
  17. self.setTextCursor(text_cursor)
  18. class LoggerGroupBox(QGroupBox):
  19. def __init__(self, parent, location_dir=None):
  20. super().__init__("Event Log", parent)
  21. if location_dir is None:
  22. location_dir = get_app_log_dir()
  23. log_dir = pl.Path(location_dir)
  24. log_dir.mkdir(exist_ok=True, parents=True)
  25. log_file = str(log_dir / f"started_at_{time.strftime('%Y-%m-%d-%H-%M-%S')}.log")
  26. vbox = QVBoxLayout(self)
  27. self.log_pte = QPlainTextEditLogger(parent)
  28. self.log_pte.setLevel(level=logging.INFO)
  29. vbox.addWidget(self.log_pte)
  30. view_logger = logging.getLogger("VIEW")
  31. view_logger.setLevel(level=logging.INFO)
  32. formatter = logging.Formatter("%(asctime)s [VIEW] [%(levelname)-5.5s] %(message)s")
  33. self.log_file_handler = logging.FileHandler(log_file)
  34. self.log_file_handler.setFormatter(formatter)
  35. self.log_file_handler.setLevel(level=logging.DEBUG)
  36. view_logger.addHandler(self.log_file_handler)
  37. self.log_pte.setFormatter(formatter)
  38. view_logger.addHandler(self.log_pte)
  39. stream_handler = logging.StreamHandler(sys.stdout)
  40. stream_handler.setLevel(level=logging.INFO)
  41. stream_handler.setFormatter(formatter)
  42. view_logger.addHandler(stream_handler)
  43. def __del__(self):
  44. root_logger = logging.getLogger("VIEW")
  45. root_logger.removeHandler(self.log_pte)
  46. root_logger.removeHandler(self.log_file_handler)