summaryrefslogtreecommitdiffstats
path: root/common/log.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-05-01 23:50:00 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-05-01 23:50:00 +0200
commit4bbb92fd179fc00258264bd488270179ff246510 (patch)
tree25e67f00ca92c3ae61c487d6bb64c600b56d3058 /common/log.cpp
parent0aee555ae75e51802e5193c96b2e492007a15a52 (diff)
downloadsink-4bbb92fd179fc00258264bd488270179ff246510.tar.gz
sink-4bbb92fd179fc00258264bd488270179ff246510.zip
Logging
Diffstat (limited to 'common/log.cpp')
-rw-r--r--common/log.cpp27
1 files changed, 22 insertions, 5 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
76QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char* function) 76QDebug 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}