|
QGIS API Documentation
master-6164ace
|
00001 /*************************************************************************** 00002 qgslogger.h - description 00003 ------------------- 00004 begin : April 2006 00005 copyright : (C) 2006 by Marco Hugentobler 00006 email : marco.hugentobler at karto dot baug dot ethz dot ch 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef QGSLOGGER_H 00019 #define QGSLOGGER_H 00020 00021 #include <iostream> 00022 #include <sstream> 00023 #include <QString> 00024 class QFile; 00025 00026 #ifdef QGISDEBUG 00027 #define QgsDebugMsg(str) QgsLogger::debug(QString(str), 1, __FILE__, __FUNCTION__, __LINE__) 00028 #define QgsDebugMsgLevel(str, level) \ 00029 { \ 00030 if ( QgsLogger::debugLevel() >= (level) && (level) > 0 ) \ 00031 QgsLogger::debug(QString(str), (level), __FILE__, __FUNCTION__, __LINE__); \ 00032 } 00033 #else 00034 #define QgsDebugMsg(str) 00035 #define QgsDebugMsgLevel(str, level) 00036 #endif 00037 00054 class CORE_EXPORT QgsLogger 00055 { 00056 public: 00057 00064 static void debug( const QString& msg, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 ); 00065 00067 static void debug( const QString& var, int val, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 ); 00068 00070 // @note not available in python bindings 00071 static void debug( const QString& var, double val, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 ); 00072 00074 // @note not available in python bindings 00075 template <typename T> static void debug( const QString& var, T val, const char* file = 0, const char* function = 0, 00076 int line = -1, int debuglevel = 1 ) 00077 { 00078 Q_UNUSED( debuglevel ); 00079 const char* dfile = debugFile(); 00080 if ( dfile ) //exit if QGIS_DEBUG_FILE is set and the message comes from the wrong file 00081 { 00082 if ( !file || strcmp( dfile, file ) != 0 ) 00083 { 00084 return; 00085 } 00086 } 00087 std::ostringstream os; 00088 os << var.toLocal8Bit().data() << " = " << val; 00089 if ( line == -1 ) 00090 { 00091 qDebug( "%s: (%s) %s", file + sPrefixLength, function, os.str().c_str() ); 00092 } 00093 else 00094 { 00095 #if defined(_MSC_VER) 00096 qDebug( "%s(%d): (%s) %s", file + sPrefixLength, line, function, os.str().c_str() ); 00097 #else 00098 qDebug( "%s: %d: (%s) %s", file + sPrefixLength, line, function, os.str().c_str() ); 00099 #endif 00100 } 00101 } 00102 00104 static void warning( const QString& msg ); 00105 00107 static void critical( const QString& msg ); 00108 00110 static void fatal( const QString& msg ); 00111 00114 static int debugLevel(); 00115 00117 static void logMessageToFile( QString theMessage ); 00118 00119 private: 00122 static const QString logFile(); 00123 00126 static const char* debugFile(); 00127 00129 static int sDebugLevel; 00130 static int sPrefixLength; 00131 }; 00132 00133 #endif