Class: QgsLogger

Responsible for printing debug/warning/error messages to the console.

The advantage of this class over iostream & co. is that the output can be controlled with environment variables: QGIS_DEBUG is an int describing what debug messages are written to the console. If the debug level of a message is <= QGIS_DEBUG, the message is written to the console. It the variable QGIS_DEBUG is not defined, it defaults to 1 for debug mode and to 0 for release mode QGIS_DEBUG_FILE may contain a file name. Only the messages from this file are printed (provided they have the right debuglevel). If QGIS_DEBUG_FILE is not set, messages from all files are printed

QGIS_LOG_FILE may contain a file name. If set, all messages will be appended to this file rather than to stdout.

List of all members, including inherited members

Static Methods

critical

Goes to qCritical.

debug

Goes to qDebug.

debugLevel

Reads the environment variable QGIS_DEBUG and converts it to int.

fatal

Goes to qFatal.

logFile

Reads the environment variable QGIS_LOG_FILE.

logMessageToFile

Logs the message passed in to the logfile defined in QGIS_LOG_FILE if any.

warning

Goes to qWarning.

class qgis.core.QgsLogger[source]

Bases: object

static critical(msg: str | None)[source]

Goes to qCritical.

Parameters:

msg (Optional[str])

static debug(msg: str | None, debuglevel: int = 1, file: str | None = None, function: str | None = None, line: int = -1)[source]

Goes to qDebug.

Parameters:
  • msg (Optional[str]) – the message to be printed

  • debuglevel (int = 1)

  • file (Optional[str] = None) – file name where the message comes from

  • function (Optional[str] = None) – function where the message comes from

  • line (int = -1) – place in file where the message comes from

debug(var: Optional[str], val: int, debuglevel: int = 1, file: Optional[str] = None, function: Optional[str] = None, line: int = -1) Similar to the previous method, but prints a variable int-value pair

static debugLevel() int[source]

Reads the environment variable QGIS_DEBUG and converts it to int. If QGIS_DEBUG is not set, the function returns 1 if QGISDEBUG is defined and 0 if not.

Return type:

int

static fatal(msg: str | None)[source]

Goes to qFatal.

Parameters:

msg (Optional[str])

static logFile() str[source]

Reads the environment variable QGIS_LOG_FILE.

Returns an empty string if the variable is not set, otherwise returns a file name for writing log messages to.

Calling this method initializes the logging system by reading the environment variables QGIS_LOG_FILE, QGIS_DEBUG, and QGIS_DEBUG_FILE.

This method must be called before any call to logMessageToFile(), otherwise messages will not be written to the log file.

Returns the log file path used by QgsLogger.

Return type:

str

static logMessageToFile(message: str | None)[source]

Logs the message passed in to the logfile defined in QGIS_LOG_FILE if any.

Parameters:

message (Optional[str])

static warning(msg: str | None)[source]

Goes to qWarning.

Parameters:

msg (Optional[str])