summaryrefslogtreecommitdiffstats
path: root/common/log.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/log.cpp')
-rw-r--r--common/log.cpp44
1 files changed, 31 insertions, 13 deletions
diff --git a/common/log.cpp b/common/log.cpp
index 316031d..85a55c0 100644
--- a/common/log.cpp
+++ b/common/log.cpp
@@ -24,11 +24,7 @@ public:
24 qint64 readLineData(char *, qint64) { return 0; /* eof */ } 24 qint64 readLineData(char *, qint64) { return 0; /* eof */ }
25 qint64 writeData(const char *data, qint64 len) 25 qint64 writeData(const char *data, qint64 len)
26 { 26 {
27 const QByteArray buf = QByteArray::fromRawData(data, len); 27 std::cout << data << std::endl;
28 // if (!qgetenv("IMAP_TRACE").isEmpty()) {
29 // qt_message_output(QtDebugMsg, buf.trimmed().constData());
30 std::cout << buf.trimmed().constData() << std::endl;
31 // }
32 return len; 28 return len;
33 } 29 }
34private: 30private:
@@ -186,24 +182,46 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char* file,
186 }; 182 };
187 183
188 bool showLocation = false; 184 bool showLocation = false;
189 bool showProgram = true; 185 bool showFunction = false;
186 bool showProgram = false;
187 bool useColor = true;
188 bool multiline = false;
190 189
191 const QString resetColor = colorCommand(ANSI_Colors::Reset); 190 const QString resetColor = colorCommand(ANSI_Colors::Reset);
192 QString output; 191 QString output;
193 output += colorCommand(QList<int>() << ANSI_Colors::Bold << prefixColorCode) + prefix + resetColor; 192 if (useColor) {
193 output += colorCommand(QList<int>() << ANSI_Colors::Bold << prefixColorCode);
194 }
195 output += prefix;
196 if (useColor) {
197 output += resetColor;
198 }
194 if (showProgram) { 199 if (showProgram) {
195 output += QString(" %1(%2)").arg(QString::fromLatin1(programName)).arg(unsigned(getpid())); 200 int width = 10;
201 output += QString(" %1(%2)").arg(QString::fromLatin1(programName).leftJustified(width, ' ', true)).arg(unsigned(getpid())).rightJustified(width + 8, ' ');
196 } 202 }
197 if (debugArea) { 203 if (debugArea) {
198 output += colorCommand(QList<int>() << ANSI_Colors::Bold << prefixColorCode) + QString(" %1 ").arg(QString::fromLatin1(debugArea)) + resetColor; 204 if (useColor) {
205 output += colorCommand(QList<int>() << ANSI_Colors::Bold << prefixColorCode);
206 }
207 output += QString(" %1 ").arg(QString::fromLatin1(debugArea).leftJustified(25, ' ', true));
208 if (useColor) {
209 output += resetColor;
210 }
211 }
212 if (showFunction) {
213 output += QString(" %3").arg(QString::fromLatin1(function).leftJustified(25, ' ', true));
199 } 214 }
200 if (showLocation) { 215 if (showLocation) {
201 output += QString(" %3").arg(function); 216 const auto filename = QString::fromLatin1(file).split('/').last();
202 output += QString("%1:%2").arg(file).arg(line); 217 output += QString(" %1:%2").arg(filename.right(25)).arg(QString::number(line).leftJustified(4, ' ')).leftJustified(30, ' ', true);
218 }
219 if (multiline) {
220 output += "\n ";
203 } 221 }
204 output += ":"; 222 output += ": ";
205 223
206 debug << output; 224 debug.noquote().nospace() << output;
207 225
208 return debug; 226 return debug;
209} 227}