Quantum GIS API Documentation  1.7.4
src/core/qgslogger.h
Go to the documentation of this file.
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 
00025 #ifdef QGISDEBUG
00026 #define QgsDebugMsg(str) QgsLogger::debug(QString(str), 1, __FILE__, __FUNCTION__, __LINE__)
00027 #define QgsDebugMsgLevel(str, level) \
00028   { \
00029     if ( QgsLogger::debugLevel() >= (level) && (level) > 0 ) \
00030       QgsLogger::debug(QString(str), (level), __FILE__, __FUNCTION__, __LINE__); \
00031   }
00032 #else
00033 #define QgsDebugMsg(str)
00034 #define QgsDebugMsgLevel(str, level)
00035 #endif
00036 
00050 class CORE_EXPORT QgsLogger
00051 {
00052   public:
00053 
00060     static void debug( const QString& msg, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 );
00061 
00063     static void debug( const QString& var, int val, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 );
00064 
00066     static void debug( const QString& var, double val, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 );
00067 
00069     template <typename T> static void debug( const QString& var, T val, const char* file = 0, const char* function = 0,
00070         int line = -1, int debuglevel = 1 )
00071     {
00072       const char* dfile = debugFile();
00073       if ( dfile ) //exit if QGIS_DEBUG_FILE is set and the message comes from the wrong file
00074       {
00075         if ( !file || strcmp( dfile, file ) != 0 )
00076         {
00077           return;
00078         }
00079       }
00080       std::ostringstream os;
00081       os << var.toLocal8Bit().data() << " = " << val;
00082       if ( line == -1 )
00083       {
00084         qDebug( "%s: (%s) %s", file, function, os.str().c_str() );
00085       }
00086       else
00087       {
00088 #if defined(_MSC_VER)
00089         qDebug( "%s(%d): (%s) %s", file, line, function, os.str().c_str() );
00090 #else
00091         qDebug( "%s: %d: (%s) %s", file, line, function, os.str().c_str() );
00092 #endif
00093       }
00094     }
00095 
00097     static void warning( const QString& msg );
00098 
00100     static void critical( const QString& msg );
00101 
00103     static void fatal( const QString& msg );
00104 
00107     static int debugLevel();
00108 
00109   private:
00110 
00112     static const char* debugFile();
00113 
00115     static int mDebugLevel;
00116 };
00117 
00118 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines