QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 #include <QTime>
25 class QFile;
26 
27 #ifdef QGISDEBUG
28 #define QgsDebugMsg(str) QgsLogger::debug(QString(str), 1, __FILE__, __FUNCTION__, __LINE__)
29 #define QgsDebugMsgLevel(str, level) QgsLogger::debug(QString(str), (level), __FILE__, __FUNCTION__, __LINE__)
30 #define QgsDebugCall QgsScopeLogger _qgsScopeLogger(__FILE__, __FUNCTION__, __LINE__)
31 #else
32 #define QgsDebugCall
33 #define QgsDebugMsg(str)
34 #define QgsDebugMsgLevel(str, level)
35 #endif
36 
53 class CORE_EXPORT QgsLogger
54 {
55  public:
56 
63  static void debug( const QString& msg, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 );
64 
66  static void debug( const QString& var, int val, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 );
67 
69  // @note not available in python bindings
70  static void debug( const QString& var, double val, int debuglevel = 1, const char* file = NULL, const char* function = NULL, int line = -1 );
71 
73  // @note not available in python bindings
74  template <typename T> static void debug( const QString& var, T val, const char* file = 0, const char* function = 0,
75  int line = -1, int debuglevel = 1 )
76  {
77  std::ostringstream os;
78  os << var.toLocal8Bit().data() << " = " << val;
79  debug( var, os.str().c_str(), file, function, line, debuglevel );
80  }
81 
83  static void warning( const QString& msg );
84 
86  static void critical( const QString& msg );
87 
89  static void fatal( const QString& msg );
90 
93  static int debugLevel() { init(); return sDebugLevel; }
94 
96  static void logMessageToFile( QString theMessage );
97 
100  static const QString logFile() { init(); return sLogFile; }
101 
102  private:
103  static void init();
104 
106  static int sDebugLevel;
107  static int sPrefixLength;
108  static QString sLogFile;
109  static QString sFileFilter;
110  static QTime sTime;
111 };
112 
114 {
115  public:
116  QgsScopeLogger( const char* file, const char* func, int line )
117  : _file( file ), _func( func ), _line( line )
118  {
119  QgsLogger::debug( "Entering.", 1, _file, _func, _line );
120  }
122  {
123  QgsLogger::debug( "Leaving.", 1, _file, _func, _line );
124  }
125  private:
126  const char *_file;
127  const char *_func;
128  int _line;
129 };
130 
131 #endif
QgsLogger is a class to print debug/warning/error messages to the console.
Definition: qgslogger.h:53
QgsScopeLogger(const char *file, const char *func, int line)
Definition: qgslogger.h:116
static void debug(const QString &var, T val, const char *file=0, const char *function=0, int line=-1, int debuglevel=1)
Prints out a variable/value pair for types with overloaded operator<<.
Definition: qgslogger.h:74
static const QString logFile()
Reads the environment variable QGIS_LOG_FILE.
Definition: qgslogger.h:100
static int debugLevel()
Reads the environment variable QGIS_DEBUG and converts it to int.
Definition: qgslogger.h:93
QString file
Definition: qgssvgcache.cpp:76
static void debug(const QString &msg, int debuglevel=1, const char *file=NULL, const char *function=NULL, int line=-1)
Goes to qDebug.
Definition: qgslogger.cpp:60