diff options
-rw-r--r-- | common/log.cpp | 27 | ||||
-rw-r--r-- | common/log.h | 2 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 13 |
3 files changed, 33 insertions, 9 deletions
diff --git a/common/log.cpp b/common/log.cpp index 5d35f40..14869bb 100644 --- a/common/log.cpp +++ b/common/log.cpp | |||
@@ -73,7 +73,7 @@ static QString colorCommand(QList<int> colorCodes) | |||
73 | return string; | 73 | return string; |
74 | } | 74 | } |
75 | 75 | ||
76 | QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char* function) | 76 | QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) |
77 | { | 77 | { |
78 | static DebugStream stream; | 78 | static DebugStream stream; |
79 | QDebug debug(&stream); | 79 | QDebug debug(&stream); |
@@ -90,25 +90,42 @@ QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char | |||
90 | int prefixColorCode = ANSI_Colors::DoNothing; | 90 | int prefixColorCode = ANSI_Colors::DoNothing; |
91 | switch (debugLevel) { | 91 | switch (debugLevel) { |
92 | case DebugLevel::Trace: | 92 | case DebugLevel::Trace: |
93 | prefix = "Trace:"; | 93 | prefix = "Trace: "; |
94 | break; | 94 | break; |
95 | case DebugLevel::Log: | 95 | case DebugLevel::Log: |
96 | prefix = "Log:"; | 96 | prefix = "Log: "; |
97 | break; | 97 | break; |
98 | case DebugLevel::Warning: | 98 | case DebugLevel::Warning: |
99 | prefix = "Warning:"; | 99 | prefix = "Warning:"; |
100 | prefixColorCode = ANSI_Colors::Red; | 100 | prefixColorCode = ANSI_Colors::Red; |
101 | break; | 101 | break; |
102 | case DebugLevel::Error: | 102 | case DebugLevel::Error: |
103 | prefix = "Error:"; | 103 | prefix = "Error: "; |
104 | prefixColorCode = ANSI_Colors::Red; | 104 | prefixColorCode = ANSI_Colors::Red; |
105 | break; | 105 | break; |
106 | default: | 106 | default: |
107 | break; | 107 | break; |
108 | }; | 108 | }; |
109 | 109 | ||
110 | bool showLocation = false; | ||
111 | bool showProgram = true; | ||
112 | |||
110 | const QString resetColor = colorCommand(ANSI_Colors::Reset); | 113 | const QString resetColor = colorCommand(ANSI_Colors::Reset); |
111 | debug << colorCommand(QList<int>() << ANSI_Colors::Bold << prefixColorCode) + prefix + resetColor + QString(" %1(%2) %3:").arg(QString::fromLatin1(programName)).arg(unsigned(getpid())).arg(function) + resetColor/* << file << ":" << line */; | 114 | QString output; |
115 | output += colorCommand(QList<int>() << ANSI_Colors::Bold << prefixColorCode) + prefix + resetColor; | ||
116 | if (showProgram) { | ||
117 | output += QString(" %1(%2)").arg(QString::fromLatin1(programName)).arg(unsigned(getpid())); | ||
118 | } | ||
119 | if (debugArea) { | ||
120 | output += colorCommand(QList<int>() << ANSI_Colors::Bold << prefixColorCode) + QString(" %1 ").arg(QString::fromLatin1(debugArea)) + resetColor; | ||
121 | } | ||
122 | if (showLocation) { | ||
123 | output += QString(" %3").arg(function); | ||
124 | /*debug << file << ":" << line */ | ||
125 | } | ||
126 | output += ":"; | ||
127 | |||
128 | debug << output; | ||
112 | 129 | ||
113 | return debug; | 130 | return debug; |
114 | } | 131 | } |
diff --git a/common/log.h b/common/log.h index e06ac5a..ee92f46 100644 --- a/common/log.h +++ b/common/log.h | |||
@@ -9,7 +9,7 @@ enum DebugLevel { | |||
9 | Error | 9 | Error |
10 | }; | 10 | }; |
11 | 11 | ||
12 | QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char* function); | 12 | QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea = 0); |
13 | 13 | ||
14 | #define Trace() debugStream(DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO) | 14 | #define Trace() debugStream(DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO) |
15 | #define Log() debugStream(DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO) | 15 | #define Log() debugStream(DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO) |
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index f448897..b7d569b 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -33,6 +33,11 @@ | |||
33 | #include <QDir> | 33 | #include <QDir> |
34 | #include <QProcess> | 34 | #include <QProcess> |
35 | 35 | ||
36 | #undef Trace | ||
37 | #define Trace() debugStream(DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess") | ||
38 | #undef Log | ||
39 | #define Log(IDENTIFIER) debugStream(DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")") | ||
40 | |||
36 | namespace Akonadi2 | 41 | namespace Akonadi2 |
37 | { | 42 | { |
38 | 43 | ||
@@ -163,6 +168,7 @@ ResourceAccess::ResourceAccess(const QByteArray &resourceName, QObject *parent) | |||
163 | 168 | ||
164 | ResourceAccess::~ResourceAccess() | 169 | ResourceAccess::~ResourceAccess() |
165 | { | 170 | { |
171 | log("Closing access"); | ||
166 | if (!d->resultHandler.isEmpty()) { | 172 | if (!d->resultHandler.isEmpty()) { |
167 | Warning() << "Left jobs running while shutting down ResourceAccess"; | 173 | Warning() << "Left jobs running while shutting down ResourceAccess"; |
168 | } | 174 | } |
@@ -310,7 +316,7 @@ void ResourceAccess::disconnected() | |||
310 | void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) | 316 | void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) |
311 | { | 317 | { |
312 | if (error == QLocalSocket::PeerClosedError) { | 318 | if (error == QLocalSocket::PeerClosedError) { |
313 | Log() << "The resource closed the connection."; | 319 | Log(d->resourceName) << "The resource closed the connection."; |
314 | } else { | 320 | } else { |
315 | Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString()); | 321 | Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString()); |
316 | } | 322 | } |
@@ -325,6 +331,7 @@ void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) | |||
325 | void ResourceAccess::readResourceMessage() | 331 | void ResourceAccess::readResourceMessage() |
326 | { | 332 | { |
327 | if (!d->socket || !d->socket->isValid()) { | 333 | if (!d->socket || !d->socket->isValid()) { |
334 | Warning() << "No socket available"; | ||
328 | return; | 335 | return; |
329 | } | 336 | } |
330 | 337 | ||
@@ -372,7 +379,7 @@ bool ResourceAccess::processMessageBuffer() | |||
372 | auto buffer = GetNotification(d->partialMessageBuffer.constData() + headerSize); | 379 | auto buffer = GetNotification(d->partialMessageBuffer.constData() + headerSize); |
373 | switch (buffer->type()) { | 380 | switch (buffer->type()) { |
374 | case Akonadi2::NotificationType::NotificationType_Shutdown: | 381 | case Akonadi2::NotificationType::NotificationType_Shutdown: |
375 | Log() << "Received shutdown notification."; | 382 | Log(d->resourceName) << "Received shutdown notification."; |
376 | close(); | 383 | close(); |
377 | break; | 384 | break; |
378 | default: | 385 | default: |
@@ -399,7 +406,7 @@ void ResourceAccess::callCallbacks(int id) | |||
399 | 406 | ||
400 | void ResourceAccess::log(const QString &message) | 407 | void ResourceAccess::log(const QString &message) |
401 | { | 408 | { |
402 | Log() << d->resourceName + ": " + message; | 409 | Log(d->resourceName) << this << message; |
403 | } | 410 | } |
404 | 411 | ||
405 | } | 412 | } |