source:
sasview/src/sas/qtgui/Utilities/SasviewLogger.py
@
1309205b
Last change on this file since 1309205b was 6138f73, checked in by Torin Cooper-Bennun <torin.cooper-bennun@…>, 6 years ago | |
---|---|
|
|
File size: 801 bytes |
Rev | Line | |
---|---|---|
[0cd8612] | 1 | import os |
2 | import sys | |
3 | import logging | |
4 | ||
[4992ff2] | 5 | from PyQt5.QtCore import * |
[0cd8612] | 6 | |
7 | ||
[41d6187] | 8 | class 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] | 24 | def 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.