18
18
19
19
#include " qgslogger.h"
20
20
#include < QtDebug>
21
+ #include < QFile>
21
22
22
23
int QgsLogger::mDebugLevel = -999 ; // undefined value
23
24
@@ -38,14 +39,17 @@ void QgsLogger::debug( const QString& msg, int debuglevel, const char* file, con
38
39
if ( file == NULL )
39
40
{
40
41
qDebug ( " %s" , msg.toLocal8Bit ().constData () );
42
+ logMessageToFile ( msg );
41
43
}
42
44
else if ( function == NULL )
43
45
{
44
46
qDebug ( " %s: %s" , file, msg.toLocal8Bit ().constData () );
47
+ logMessageToFile ( msg );
45
48
}
46
49
else if ( line == -1 )
47
50
{
48
51
qDebug ( " %s: (%s) %s" , file, function, msg.toLocal8Bit ().constData () );
52
+ logMessageToFile ( msg );
49
53
}
50
54
else
51
55
{
@@ -54,6 +58,7 @@ void QgsLogger::debug( const QString& msg, int debuglevel, const char* file, con
54
58
#else
55
59
qDebug ( " %s(%d) : (%s) %s" , file, line, function, msg.toLocal8Bit ().constData () );
56
60
#endif
61
+ logMessageToFile ( msg );
57
62
}
58
63
}
59
64
}
@@ -75,14 +80,17 @@ void QgsLogger::debug( const QString& var, int val, int debuglevel, const char*
75
80
if ( file == NULL )
76
81
{
77
82
qDebug ( " %s: %d" , var.toLocal8Bit ().constData (), val );
83
+ logMessageToFile ( QString ( " %s: %d" ).arg ( var.toLocal8Bit ().constData () ).arg ( val ) );
78
84
}
79
85
else if ( function == NULL )
80
86
{
81
87
qDebug ( " %s: %s: %d" , file, var.toLocal8Bit ().constData (), val );
88
+ logMessageToFile ( QString ( " %s: %s: %d" ).arg ( file ).arg ( var.toLocal8Bit ().constData () ).arg ( val ) );
82
89
}
83
90
else if ( line == -1 )
84
91
{
85
92
qDebug ( " %s: (%s): %s: %d" , file, function, var.toLocal8Bit ().constData (), val );
93
+ logMessageToFile ( QString ( " %s: (%s): %s: %d" ).arg ( file ).arg ( function ).arg ( var.toLocal8Bit ().constData () ).arg ( val ) );
86
94
}
87
95
else
88
96
{
@@ -91,6 +99,7 @@ void QgsLogger::debug( const QString& var, int val, int debuglevel, const char*
91
99
#else
92
100
qDebug ( " %s: %d: (%s), %s: %d" , file, line, function, var.toLocal8Bit ().constData (), val );
93
101
#endif
102
+ logMessageToFile ( QString ( " %s: %d: (%s), %s: %d" ).arg ( file ).arg ( line ).arg ( function ).arg ( var.toLocal8Bit ().constData () ).arg ( val ) );
94
103
}
95
104
}
96
105
}
@@ -112,14 +121,17 @@ void QgsLogger::debug( const QString& var, double val, int debuglevel, const cha
112
121
if ( file == NULL )
113
122
{
114
123
qDebug ( " %s: %f" , var.toLocal8Bit ().constData (), val );
124
+ logMessageToFile ( QString ( " %s: %f" ).arg ( var.toLocal8Bit ().constData () ).arg ( val ) );
115
125
}
116
126
else if ( function == NULL )
117
127
{
118
128
qDebug ( " %s: %s: %f" , file, var.toLocal8Bit ().constData (), val );
129
+ logMessageToFile ( QString ( " %s: %s: %f" ).arg ( file ).arg ( var.toLocal8Bit ().constData () ).arg ( val ) );
119
130
}
120
131
else if ( line == -1 )
121
132
{
122
133
qDebug ( " %s: (%s): %s: %f" , file, function, var.toLocal8Bit ().constData (), val );
134
+ logMessageToFile ( QString ( " %s: (%s): %s: %f" ).arg ( file ).arg ( function ).arg ( var.toLocal8Bit ().constData () ).arg ( val ) );
123
135
}
124
136
else
125
137
{
@@ -128,23 +140,27 @@ void QgsLogger::debug( const QString& var, double val, int debuglevel, const cha
128
140
#else
129
141
qDebug ( " %s: %d: (%s), %s: %f" , file, line, function, var.toLocal8Bit ().constData (), val );
130
142
#endif
143
+ logMessageToFile ( QString ( " %s: %d: (%s), %s: %f" ).arg ( file ).arg ( line ).arg ( function ).arg ( var.toLocal8Bit ().constData () ).arg ( val ) );
131
144
}
132
145
}
133
146
}
134
147
135
148
void QgsLogger::warning ( const QString& msg )
136
149
{
137
150
qWarning ( " %s" , msg.toLocal8Bit ().constData () );
151
+ logMessageToFile ( msg );
138
152
}
139
153
140
154
void QgsLogger::critical ( const QString& msg )
141
155
{
142
156
qCritical ( " %s" , msg.toLocal8Bit ().constData () );
157
+ logMessageToFile ( msg );
143
158
}
144
159
145
160
void QgsLogger::fatal ( const QString& msg )
146
161
{
147
162
qFatal ( " %s" , msg.toLocal8Bit ().constData () );
163
+ logMessageToFile ( msg );
148
164
}
149
165
150
166
int QgsLogger::debugLevel ()
@@ -178,6 +194,26 @@ int QgsLogger::debugLevel()
178
194
return mDebugLevel ;
179
195
}
180
196
197
+ const QString QgsLogger::logFile ()
198
+ {
199
+ const QString logFile = getenv ( " QGIS_LOG_FILE" );
200
+ return logFile;
201
+ }
202
+
203
+ const void QgsLogger::logMessageToFile ( QString theMessage )
204
+ {
205
+ if ( ! logFile ().isEmpty () )
206
+ {
207
+ // Maybe more efficient to keep the file open for the life of qgis...
208
+ QFile file ( logFile () );
209
+ file.open (QIODevice::Append);
210
+ file.write ( theMessage.toStdString ().c_str () );
211
+ file.write ( " \n " );
212
+ file.close ();
213
+ }
214
+ return ;
215
+ }
216
+
181
217
const char * QgsLogger::debugFile ()
182
218
{
183
219
const char * dfile = getenv ( " QGIS_DEBUG_FILE" );
0 commit comments