source: sasview/src/sas/qtgui/Utilities/SasviewLogger.py @ e4335ae

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since e4335ae was e4335ae, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 6 years ago

SASVIEW-957 logging changes (#158)

  • rework XStream to continue to write to stdout/stderr alongside redirection; make logging level setting consistent; make log configuration more consistent
  • rm XStream; QT signal in QtHandler? logging handler; only logs in Log Explorer (no stdout/stderr)
  • no need to change handler level
  • use QTextBrowser.append to facilitate auto-scrolling in the Log Explorer
  • modify logger unit test to reflect changes (passes)
  • Property mode set to 100644
File size: 801 bytes
RevLine 
[0cd8612]1import os
2import sys
3import logging
4
[4992ff2]5from PyQt5.QtCore import *
[0cd8612]6
7
[e4335ae]8class QtHandler(QObject, logging.Handler):
[0cd8612]9    """
[e4335ae]10    Version of logging handler "emitting" the message to custom stdout()
[0cd8612]11    """
[e4335ae]12    messageWritten = pyqtSignal(str)
13
[0cd8612]14    def __init__(self):
[e4335ae]15        QObject.__init__(self)
[0cd8612]16        logging.Handler.__init__(self)
17
18    def emit(self, record):
19        record = self.format(record)
20        if record:
[e4335ae]21            self.messageWritten.emit('%s\n'%record)
22
[0cd8612]23
[e4335ae]24def setup_qt_logging():
25    # Define the default logger
26    logger = logging.getLogger()
[0cd8612]27
[e4335ae]28    # Add the qt-signal logger
29    handler = QtHandler()
30    handler.setFormatter(logging.Formatter(
31        fmt="%(asctime)s - %(levelname)s: %(message)s",
32        datefmt="%H:%M:%S"
33    ))
34    logger.addHandler(handler)
[0cd8612]35
[e4335ae]36    return handler
Note: See TracBrowser for help on using the repository browser.