21 #include <QApplication> 26 #include "qgsconfig.h" 28 #ifndef CMAKE_SOURCE_DIR 29 #error CMAKE_SOURCE_DIR undefined 30 #endif // CMAKE_SOURCE_DIR 32 int QgsLogger::sDebugLevel = -999;
33 int QgsLogger::sPrefixLength = -1;
36 QTime QgsLogger::sTime;
38 void QgsLogger::init()
40 if ( sDebugLevel != -999 )
45 sLogFile = getenv(
"QGIS_LOG_FILE" ) ? getenv(
"QGIS_LOG_FILE" ) :
"";
46 sFileFilter = getenv(
"QGIS_DEBUG_FILE" ) ? getenv(
"QGIS_DEBUG_FILE" ) :
"";
47 sDebugLevel = getenv(
"QGIS_DEBUG" ) ? atoi( getenv(
"QGIS_DEBUG" ) ) :
55 sPrefixLength =
sizeof( CMAKE_SOURCE_DIR );
56 if ( CMAKE_SOURCE_DIR[sPrefixLength-1] ==
'/' )
67 if ( sDebugLevel == 0 || debuglevel > sDebugLevel )
98 m.
prepend( file + ( file[0] ==
'/' ? sPrefixLength : 0 ) );
116 debug(
QString(
"%1: %2" ).arg( var ).arg( val ), debuglevel, file,
function, line );
121 debug(
QString(
"%1: %2" ).arg( var ).arg( val ), debuglevel, file,
function, line );
148 QFile file( sLogFile );
149 if ( !file.
open( QIODevice::Append ) )
static void critical(const QString &msg)
Goes to qCritical.
QString & prepend(QChar ch)
static void warning(const QString &msg)
Goes to qWarning.
static void debug(const QString &msg, int debuglevel=1, const char *file=nullptr, const char *function=nullptr, int line=-1)
Goes to qDebug.
const char * constData() const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
static void fatal(const QString &msg)
Goes to qFatal.
QByteArray toLocal8Bit() const
QThread * currentThread()
static void logMessageToFile(const QString &theMessage)
Logs the message passed in to the logfile defined in QGIS_LOG_FILE if any.
qint64 write(const char *data, qint64 maxSize)
QByteArray toUtf8() const