summaryrefslogtreecommitdiffstats
path: root/common/log.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/log.cpp')
-rw-r--r--common/log.cpp43
1 files changed, 41 insertions, 2 deletions
diff --git a/common/log.cpp b/common/log.cpp
index 95a9c01..1fe09be 100644
--- a/common/log.cpp
+++ b/common/log.cpp
@@ -6,6 +6,8 @@
6#include <iostream> 6#include <iostream>
7#include <unistd.h> 7#include <unistd.h>
8 8
9using namespace Akonadi2::Log;
10
9class DebugStream: public QIODevice 11class DebugStream: public QIODevice
10{ 12{
11public: 13public:
@@ -94,9 +96,46 @@ static QString colorCommand(QList<int> colorCodes)
94 return string; 96 return string;
95} 97}
96 98
97QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) 99QByteArray debugLevelName(DebugLevel debugLevel)
100{
101 switch (debugLevel) {
102 case DebugLevel::Trace:
103 return "Trace";
104 case DebugLevel::Log:
105 return "Log";
106 case DebugLevel::Warning:
107 return "Warning";
108 case DebugLevel::Error:
109 return "Error";
110 default:
111 break;
112 };
113 Q_ASSERT(false);
114 return QByteArray();
115}
116
117DebugLevel debugLevelFromName(const QByteArray &name)
118{
119 if (name.toLower() == "trace")
120 return DebugLevel::Trace;
121 if (name.toLower() == "log")
122 return DebugLevel::Log;
123 if (name.toLower() == "warning")
124 return DebugLevel::Warning;
125 if (name.toLower() == "error")
126 return DebugLevel::Error;
127 return DebugLevel::Log;
128}
129
130void Akonadi2::Log::setDebugOutputLevel(DebugLevel debugLevel)
131{
132 qputenv("AKONADI2DEBUGLEVEL", debugLevelName(debugLevel));
133}
134
135QDebug Akonadi2::Log::debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea)
98{ 136{
99 if (debugLevel <= DebugLevel::Trace) { 137 DebugLevel debugOutputLevel = debugLevelFromName(qgetenv("AKONADI2DEBUGLEVEL"));
138 if (debugLevel < debugOutputLevel) {
100 static NullStream stream; 139 static NullStream stream;
101 return QDebug(&stream); 140 return QDebug(&stream);
102 } 141 }