/
qgslogger.cpp
160 lines (146 loc) · 4.33 KB
/
qgslogger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/***************************************************************************
qgslogger.cpp - description
-------------------
begin : April 2006
copyright : (C) 2006 by Marco Hugentobler
email : marco.hugentobler at karto dot baug dot ethz dot ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgslogger.h"
void QgsLogger::debug(const QString& msg, int debuglevel, const char* file, const char* function, int line)
{
const char* dfile = debugFile();
if(dfile) //exit if QGIS_DEBUG_FILE is set and the message comes from the wrong file
{
if(!file || strcmp(dfile, file) != 0)
{
return;
}
}
int dlevel = debugLevel();
if(dlevel >= debuglevel && debuglevel > 0)
{
if(file == NULL)
{
qDebug(msg.toLocal8Bit().data());
}
else if(function == NULL)
{
qDebug("File: %s, Message: %s", file, msg.toLocal8Bit().data());
}
else if(line == -1)
{
qDebug("File: %s, Function: %s, Message: %s", file, function, msg.toLocal8Bit().data());
}
else
{
qDebug("File: %s, Function: %s, Line: %d, Message: %s", file, function, line, msg.toLocal8Bit().data());
}
}
}
void QgsLogger::debug(const QString& var, int val, int debuglevel, const char* file, const char* function, int line)
{
const char* dfile = debugFile();
if(dfile) //exit if QGIS_DEBUG_FILE is set and the message comes from the wrong file
{
if(!file || strcmp(dfile, file) != 0)
{
return;
}
}
int dlevel = debugLevel();
if(dlevel >= debuglevel && debuglevel > 0)
{
if(file == NULL)
{
qDebug("Variable: %s, Value: %d", var.toLocal8Bit().data(), val);
}
else if(function == NULL)
{
qDebug("File: %s, Variable: %s, Value: %d", file, var.toLocal8Bit().data(), val);
}
else if(line == -1)
{
qDebug("File: %s, Function: %s, Variable: %s, Value: %d", file, function, var.toLocal8Bit().data(), val);
}
else
{
qDebug("File: %s, Function: %s, Line: %d, Variable: %s, Value: %d", file, function, line, var.toLocal8Bit().data(), val);
}
}
}
void QgsLogger::debug(const QString& var, double val, int debuglevel, const char* file, const char* function, int line)
{
const char* dfile = debugFile();
if(dfile) //exit if QGIS_DEBUG_FILE is set and the message comes from the wrong file
{
if(!file || strcmp(dfile, file) != 0)
{
return;
}
}
int dlevel = debugLevel();
if(dlevel >= debuglevel && debuglevel > 0)
{
if(file == NULL)
{
qDebug("Variable: %s, Value: %f", var.toLocal8Bit().data(), val);
}
else if(function == NULL)
{
qDebug("File: %s, Variable: %s, Value: %f", file, var.toLocal8Bit().data(), val);
}
else if(line == -1)
{
qDebug("File: %s, Function: %s, Variable: %s, Value: %f", file, function, var.toLocal8Bit().data(), val);
}
else
{
qDebug("File: %s, Function: %s, Line: %d, Variable: %s, Value: %f", file, function, line, var.toLocal8Bit().data(), val);
}
}
}
void QgsLogger::warning(const QString& msg)
{
qWarning(msg.toLocal8Bit().data());
}
void QgsLogger::critical(const QString& msg)
{
qCritical(msg.toLocal8Bit().data());
}
void QgsLogger::fatal(const QString& msg)
{
qFatal(msg.toLocal8Bit().data());
}
int QgsLogger::debugLevel()
{
const char* dlevel = getenv("QGIS_DEBUG");
if(dlevel == NULL) //environment variable not set
{
#ifdef QGISDEBUG
return 1; //1 is default value in debug mode
#else
return 0;
#endif
}
int level = atoi(dlevel);
#ifdef QGISDEBUG
if(level == 0)
{
level = 1;
}
#endif
return level;
}
const char* QgsLogger::debugFile()
{
const char* dfile = getenv("QGIS_DEBUG_FILE");
return dfile;
}