Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgslogger.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslogger.h - description
3  -------------------
4  begin : April 2006
5  copyright : (C) 2006 by Marco Hugentobler
6  email : marco.hugentobler at karto dot baug dot ethz dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSLOGGER_H
19 #define QGSLOGGER_H
20 
21 #include <iostream>
22 #include <sstream>
23 #include <QString>
24 
25 #ifdef QGISDEBUG
26 #define QgsDebugMsg(str) QgsLogger::debug(QString(str), 1, __FILE__, __FUNCTION__, __LINE__)
27 #define QgsDebugMsgLevel(str, level) \
28  { \
29  if ( QgsLogger::debugLevel() >= (level) && (level) > 0 ) \
30  QgsLogger::debug(QString(str), (level), __FILE__, __FUNCTION__, __LINE__); \
31  }
32 #else
33 #define QgsDebugMsg(str)
34 #define QgsDebugMsgLevel(str, level)
35 #endif
36 
50 class CORE_EXPORT QgsLogger
51 {
52  public:
53 
60  static void debug( const QString& msg, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 );
61 
63  static void debug( const QString& var, int val, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 );
64 
66  static void debug( const QString& var, double val, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 );
67 
69  template <typename T> static void debug( const QString& var, T val, const char* file = 0, const char* function = 0,
70  int line = -1, int debuglevel = 1 )
71  {
72  const char* dfile = debugFile();
73  if ( dfile ) //exit if QGIS_DEBUG_FILE is set and the message comes from the wrong file
74  {
75  if ( !file || strcmp( dfile, file ) != 0 )
76  {
77  return;
78  }
79  }
80  std::ostringstream os;
81  os << var.toLocal8Bit().data() << " = " << val;
82  if ( line == -1 )
83  {
84  qDebug( "%s: (%s) %s", file, function, os.str().c_str() );
85  }
86  else
87  {
88 #if defined(_MSC_VER)
89  qDebug( "%s(%d): (%s) %s", file, line, function, os.str().c_str() );
90 #else
91  qDebug( "%s: %d: (%s) %s", file, line, function, os.str().c_str() );
92 #endif
93  }
94  }
95 
97  static void warning( const QString& msg );
98 
100  static void critical( const QString& msg );
101 
103  static void fatal( const QString& msg );
104 
107  static int debugLevel();
108 
109  private:
110 
112  static const char* debugFile();
113 
115  static int mDebugLevel;
116 };
117 
118 #endif