Quantum GIS API Documentation
1.8
|
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 static void debug( const QString& var, double val, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 ); 00071 00073 template <typename T> static void debug( const QString& var, T val, const char* file = 0, const char* function = 0, 00074 int line = -1, int debuglevel = 1 ) 00075 { 00076 Q_UNUSED( debuglevel ); 00077 const char* dfile = debugFile(); 00078 if ( dfile ) //exit if QGIS_DEBUG_FILE is set and the message comes from the wrong file 00079 { 00080 if ( !file || strcmp( dfile, file ) != 0 ) 00081 { 00082 return; 00083 } 00084 } 00085 std::ostringstream os; 00086 os << var.toLocal8Bit().data() << " = " << val; 00087 if ( line == -1 ) 00088 { 00089 qDebug( "%s: (%s) %s", file + sPrefixLength, function, os.str().c_str() ); 00090 } 00091 else 00092 { 00093 #if defined(_MSC_VER) 00094 qDebug( "%s(%d): (%s) %s", file + sPrefixLength, line, function, os.str().c_str() ); 00095 #else 00096 qDebug( "%s: %d: (%s) %s", file + sPrefixLength, line, function, os.str().c_str() ); 00097 #endif 00098 } 00099 } 00100 00102 static void warning( const QString& msg ); 00103 00105 static void critical( const QString& msg ); 00106 00108 static void fatal( const QString& msg ); 00109 00112 static int debugLevel(); 00113 00115 static void logMessageToFile( QString theMessage ); 00116 00117 private: 00120 static const QString logFile(); 00121 00124 static const char* debugFile(); 00125 00127 static int sDebugLevel; 00128 static int sPrefixLength; 00129 }; 00130 00131 #endif