PySide6.QtCore.QMessageLogger

class QMessageLogger

The QMessageLogger class generates log messages. More

Synopsis

Methods

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

Detailed Description

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

QMessageLogger is used to generate messages for the Qt logging framework. Usually one uses it through qDebug() , qInfo() , qWarning() , qCritical , or qFatal() functions, which are actually macros: For example qDebug() expands to QMessageLogger (__FILE__, __LINE__, Q_FUNC_INFO ). debug() for debug builds, and QMessageLogger (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

QMessageLogContext qDebug() qInfo() qWarning() qCritical() qFatal()

In Python, the QMessageLogger is 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")
__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 QMessageLogger to record log messages for file at line in function. The is equivalent to QMessageLogger (file, line, function, “default”)

__init__(file, line, function, category)
Parameters:
  • file – str

  • line – int

  • function – str

  • category – str

Constructs a QMessageLogger to record category messages for file at line in function.

See also

QLoggingCategory

critical(msg)
Parameters:

msg – str

critical(cat, msg)
Parameters:

Logs a critical message specified with format msg. Additional parameters, specified by msg, may be used.

See also

qCritical()

debug(msg)
Parameters:

msg – str

debug(cat, msg)
Parameters:

Logs a debug message specified with format msg. Additional parameters, specified by msg, may be used.

See also

qDebug()

fatal(msg)
Parameters:

msg – str

fatal(cat, msg)
Parameters:

Logs a fatal message specified with format msg. Additional parameters, specified by msg, may be used.

See also

qFatal()

info(msg)
Parameters:

msg – str

info(cat, msg)
Parameters:

Logs an informational message specified with format msg. Additional parameters, specified by msg, may be used.

See also

qInfo()

noDebug(arg__1)
Parameters:

arg__1 – str

warning(msg)
Parameters:

msg – str

warning(cat, msg)
Parameters:

Logs a warning message specified with format msg. Additional parameters, specified by msg, may be used.

See also

qWarning()