PySide6.QtCore.QMessageLogger¶
- class QMessageLogger¶
The
QMessageLoggerclass generates log messages.Details
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
QMessageLoggeris used to generate messages for the Qt logging framework. Usually one uses it throughqDebug(),qInfo(),qWarning(),qCritical, orqFatal()functions, which are actually macros: For exampleqDebug()expands toQMessageLogger(__FILE__, __LINE__,Q_FUNC_INFO).debug()for debug builds, andQMessageLogger(0, 0, 0).debug()for release builds.One example of direct use is to forward errors that stem from a scripting language, e.g. QML:
def statusChanged(status): if status == QQmlComponent.Error: for error in component.errors(): file = error.url().toEncoded() QMessageLogger(file.constData(), error.line(), 0).debug() << error.description()
See also
QMessageLogContextqDebug()qInfo()qWarning()qCritical()qFatal()In Python, the
QMessageLoggeris useful to connect an existing logging setup that uses the Python logging module to the Qt logging system. This allows you to leverage Qt’s logging infrastructure while still using the familiar Python logging API.Example:
import logging from PySide6.QtCore import QMessageLogger class LogHandler(logging.Handler): def emit(self, record: logging.LogRecord): if record.levelno == logging.DEBUG: logger = QMessageLogger(record.filename, record.lineno, record.funcName) logger.debug(record.message) logging.basicConfig(handlers=[LogHandler()]) logging.debug("Test debug message")
Synopsis¶
Methods¶
def
__init__()def
critical()def
debug()def
fatal()def
info()def
noDebug()def
warning()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
- __init__()¶
Constructs a default
QMessageLogger. See the other constructors to specify context information.- __init__(file, line, function)
- Parameters:
file – str
line – int
function – str
Constructs a
QMessageLoggerto record log messages forfileatlineinfunction. The is equivalent toQMessageLogger(file, line, function, “default”)- __init__(file, line, function, category)
- Parameters:
file – str
line – int
function – str
category – str
Constructs a
QMessageLoggerto recordcategorymessages forfileatlineinfunction.See also
- critical(msg)¶
- Parameters:
msg – str
- critical(cat, msg)
- Parameters:
cat –
QLoggingCategorymsg – str
Logs a critical message specified with format
msg. Additional parameters, specified bymsg, may be used.See also
qCritical()- debug(msg)¶
- Parameters:
msg – str
- debug(cat, msg)
- Parameters:
cat –
QLoggingCategorymsg – str
Logs a debug message specified with format
msg. Additional parameters, specified bymsg, may be used.See also
qDebug()- fatal(msg)¶
- Parameters:
msg – str
- fatal(cat, msg)
- Parameters:
cat –
QLoggingCategorymsg – str
Logs a fatal message specified with format
msg. Additional parameters, specified bymsg, may be used.See also
qFatal()- info(msg)¶
- Parameters:
msg – str
- info(cat, msg)
- Parameters:
cat –
QLoggingCategorymsg – str
Logs an informational message specified with format
msg. Additional parameters, specified bymsg, may be used.See also
qInfo()- noDebug(arg__1)¶
- Parameters:
arg__1 – str
- warning(msg)¶
- Parameters:
msg – str
- warning(cat, msg)
- Parameters:
cat –
QLoggingCategorymsg – str
Logs a warning message specified with format
msg. Additional parameters, specified bymsg, may be used.See also
qWarning()