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

Last change on this file since 46ca1f4 was 6138f73, checked in by Torin Cooper-Bennun <torin.cooper-bennun@…>, 6 years ago

no need to change handler level

  • 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
[41d6187]8class QtHandler(QObject, logging.Handler):
[5dba493]9    """
[41d6187]10    Version of logging handler "emitting" the message to custom stdout()
[5dba493]11    """
[4992ff2]12    messageWritten = pyqtSignal(str)
[0cd8612]13
14    def __init__(self):
[41d6187]15        QObject.__init__(self)
[0cd8612]16        logging.Handler.__init__(self)
17
18    def emit(self, record):
19        record = self.format(record)
20        if record:
[41d6187]21            self.messageWritten.emit('%s\n'%record)
22
[0cd8612]23
[41d6187]24def setup_qt_logging():
25    # Define the default logger
26    logger = logging.getLogger()
[0cd8612]27
[41d6187]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
[41d6187]36    return handler
Note: See TracBrowser for help on using the repository browser.