summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/log.cpp44
-rw-r--r--common/log.h18
2 files changed, 45 insertions, 17 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}
diff --git a/common/log.h b/common/log.h
index e43ef0a..564c574 100644
--- a/common/log.h
+++ b/common/log.h
@@ -24,8 +24,18 @@ QDebug SINKCOMMON_EXPORT debugStream(DebugLevel debugLevel, int line, const char
24} 24}
25} 25}
26 26
27#define Trace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO) 27#define DEBUG_AREA 0
28#define Log() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO) 28
29#define Warning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO) 29#define Trace_() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO)
30#define Log_() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO)
31
32#define Trace_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
33#define Log_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
34#define Warning_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
35#define Error_area(AREA) Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, AREA)
36
37#define Trace() Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA)
38#define Log() Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA)
39#define Warning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA)
30//FIXME Error clashes with Storage::Error and MessageQueue::Error 40//FIXME Error clashes with Storage::Error and MessageQueue::Error
31#define ErrorMsg() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO) 41#define ErrorMsg() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, DEBUG_AREA)