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
|
Line | |
---|
1 | import os |
---|
2 | import sys |
---|
3 | import logging |
---|
4 | |
---|
5 | from PyQt5.QtCore import * |
---|
6 | |
---|
7 | |
---|
8 | class QtHandler(QObject, logging.Handler): |
---|
9 | """ |
---|
10 | Version of logging handler "emitting" the message to custom stdout() |
---|
11 | """ |
---|
12 | messageWritten = pyqtSignal(str) |
---|
13 | |
---|
14 | def __init__(self): |
---|
15 | QObject.__init__(self) |
---|
16 | logging.Handler.__init__(self) |
---|
17 | |
---|
18 | def emit(self, record): |
---|
19 | record = self.format(record) |
---|
20 | if record: |
---|
21 | self.messageWritten.emit('%s\n'%record) |
---|
22 | |
---|
23 | |
---|
24 | def setup_qt_logging(): |
---|
25 | # Define the default logger |
---|
26 | logger = logging.getLogger() |
---|
27 | |
---|
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) |
---|
35 | |
---|
36 | return handler |
---|
Note: See
TracBrowser
for help on using the repository browser.