Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.8.2
-
None
Description
Qt provides the QMessageLogger class to explicitly set the source location for a given logging call. This class is not available as a Python binding.
My usecase would be to connect an existing logging setup utilizing Pythons builtin logging module to the Qt logging system.
For this I am installing a custom logging handler that would then extract the source location from the logging.LogRecord object and override the Qt logging source location.
However, without the availability of QMessageLogger in PySide only the regular qDebug etc. functions are available which report an unknown source location.
AFAIK there is also no other way to set the source location when logging.
I also tried getting the current logging message handler using qInstallMessageHandler, however, the function always seems to return None instead of the current handler.
I would have then called this handler explicitly in the callback provided to pythons logging system.
Maybe it would be possible to make QMessageLogger available in PySide.
Thank you!
QMessageLogger example
import logging from PySide6.QtCore import QMessageLogger # NameError: name 'QMessageLogger' is not defined class LogHandler(logging.Handler): def emit(self, record: logging.LogRecord): logger = QMessageLogger(record.filename, record.lineno, record.funcName) match record.levelno: case logging.WARNING: logger.warning(record.message) logging.basicConfig(handlers=[LogHandler()]) logging.warning("Test")
qInstallMessageHandler example:
from PySide6.QtCore import qInstallMessageHandler def test(*pos): print(pos) handler = qInstallMessageHandler(test) print(type(handler)) # <class 'NoneType'>
Attachments
Issue Links
- relates to
-
PYSIDE-1899 Can't use category based logging from PySide
-
- Closed
-
Gerrit Reviews
For Gerrit Dashboard: PYSIDE-3052 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
633247,8 | PySide6: Add class QMessageLogger | dev | pyside/pyside-setup | Status: NEW | +1 | 0 |
633768,6 | PySide6: Fix return type of qInstallMessageHandler | dev | pyside/pyside-setup | Status: NEW | 0 | 0 |