QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
Static Public Member Functions | List of all members
QgsLogger Class Reference

QgsLogger is a class to print debug/warning/error messages to the console. More...

#include <qgslogger.h>

Static Public Member Functions

static void critical (const QString &msg)
 Goes to qCritical. More...
 
static void debug (const QString &msg, int debuglevel=1, const char *file=nullptr, const char *function=nullptr, int line=-1)
 Goes to qDebug. More...
 
static void debug (const QString &var, double val, int debuglevel=1, const char *file=nullptr, const char *function=nullptr, int line=-1)
 Similar to the previous method, but prints a variable double-value pair. More...
 
static void debug (const QString &var, int val, int debuglevel=1, const char *file=nullptr, const char *function=nullptr, int line=-1)
 Similar to the previous method, but prints a variable int-value pair. More...
 
template<typename T >
static void debug (const QString &var, T val, const char *file=nullptr, const char *function=nullptr, int line=-1, int debuglevel=1)
 Prints out a variable/value pair for types with overloaded operator<<. More...
 
static int debugLevel ()
 Reads the environment variable QGIS_DEBUG and converts it to int. More...
 
static void fatal (const QString &msg)
 Goes to qFatal. More...
 
static QString logFile ()
 Reads the environment variable QGIS_LOG_FILE. More...
 
static void logMessageToFile (const QString &message)
 Logs the message passed in to the logfile defined in QGIS_LOG_FILE if any. More...
 
static void warning (const QString &msg)
 Goes to qWarning. More...
 

Detailed Description

QgsLogger is a class to print 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.

Definition at line 60 of file qgslogger.h.

Member Function Documentation

◆ critical()

void QgsLogger::critical ( const QString &  msg)
static

Goes to qCritical.

Definition at line 128 of file qgslogger.cpp.

◆ debug() [1/4]

void QgsLogger::debug ( const QString &  msg,
int  debuglevel = 1,
const char *  file = nullptr,
const char *  function = nullptr,
int  line = -1 
)
static

Goes to qDebug.

Parameters
msgthe message to be printed
debuglevel
filefile name where the message comes from
functionfunction where the message comes from
lineplace in file where the message comes from

Definition at line 58 of file qgslogger.cpp.

◆ debug() [2/4]

void QgsLogger::debug ( const QString &  var,
double  val,
int  debuglevel = 1,
const char *  file = nullptr,
const char *  function = nullptr,
int  line = -1 
)
static

Similar to the previous method, but prints a variable double-value pair.

Note
not available in Python bindings

Definition at line 117 of file qgslogger.cpp.

◆ debug() [3/4]

void QgsLogger::debug ( const QString &  var,
int  val,
int  debuglevel = 1,
const char *  file = nullptr,
const char *  function = nullptr,
int  line = -1 
)
static

Similar to the previous method, but prints a variable int-value pair.

Definition at line 112 of file qgslogger.cpp.

◆ debug() [4/4]

template<typename T >
static void QgsLogger::debug ( const QString &  var,
val,
const char *  file = nullptr,
const char *  function = nullptr,
int  line = -1,
int  debuglevel = 1 
)
inlinestatic

Prints out a variable/value pair for types with overloaded operator<<.

Note
not available in Python bindings

Definition at line 87 of file qgslogger.h.

◆ debugLevel()

static int QgsLogger::debugLevel ( )
inlinestatic

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.

Definition at line 108 of file qgslogger.h.

◆ fatal()

void QgsLogger::fatal ( const QString &  msg)
static

Goes to qFatal.

Definition at line 134 of file qgslogger.cpp.

◆ logFile()

QString QgsLogger::logFile ( )
static

Reads the environment variable QGIS_LOG_FILE.

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

Definition at line 154 of file qgslogger.cpp.

◆ logMessageToFile()

void QgsLogger::logMessageToFile ( const QString &  message)
static

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

Definition at line 140 of file qgslogger.cpp.

◆ warning()

void QgsLogger::warning ( const QString &  msg)
static

Goes to qWarning.

Definition at line 122 of file qgslogger.cpp.


The documentation for this class was generated from the following files: