summaryrefslogtreecommitdiff
path: root/src/core/common/Logger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/common/Logger.cpp')
-rw-r--r--src/core/common/Logger.cpp143
1 files changed, 9 insertions, 134 deletions
diff --git a/src/core/common/Logger.cpp b/src/core/common/Logger.cpp
index aa61e6a..54156f2 100644
--- a/src/core/common/Logger.cpp
+++ b/src/core/common/Logger.cpp
@@ -20,8 +20,6 @@
#include <sstream>
#include "Logger.hpp"
-#include "Terminal.hpp"
-#include "Utils.hpp"
namespace ousia {
@@ -118,49 +116,49 @@ void LoggerFork::commit()
purge();
}
-/* Class ScopedLogger */
+/* Class GuardedLogger */
-ScopedLogger::ScopedLogger(Logger &parent, SourceLocation loc)
+GuardedLogger::GuardedLogger(Logger &parent, SourceLocation loc)
: parent(parent), depth(0)
{
pushDefaultLocation(loc);
}
-ScopedLogger::~ScopedLogger()
+GuardedLogger::~GuardedLogger()
{
while (depth > 0) {
popDefaultLocation();
}
}
-void ScopedLogger::processMessage(const Message &msg)
+void GuardedLogger::processMessage(const Message &msg)
{
parent.processMessage(msg);
}
-bool ScopedLogger::filterMessage(const Message &msg)
+bool GuardedLogger::filterMessage(const Message &msg)
{
return parent.filterMessage(msg);
}
-void ScopedLogger::processPushDefaultLocation(const SourceLocation &loc)
+void GuardedLogger::processPushDefaultLocation(const SourceLocation &loc)
{
parent.processPushDefaultLocation(loc);
depth++;
}
-void ScopedLogger::processPopDefaultLocation()
+void GuardedLogger::processPopDefaultLocation()
{
depth--;
parent.processPopDefaultLocation();
}
-void ScopedLogger::processSetDefaultLocation(const SourceLocation &loc)
+void GuardedLogger::processSetDefaultLocation(const SourceLocation &loc)
{
parent.processSetDefaultLocation(loc);
}
-void ScopedLogger::processSetSourceContextCallback(
+void GuardedLogger::processSetSourceContextCallback(
SourceContextCallback sourceContextCallback)
{
parent.processSetSourceContextCallback(sourceContextCallback);
@@ -265,128 +263,5 @@ bool ConcreteLogger::hasFatalError()
return getSeverityCount(Severity::FATAL_ERROR) > 0;
}
-/* Class TerminalLogger */
-
-void TerminalLogger::processMessage(const Message &msg)
-{
- Terminal t(useColor);
-
- // Fetch filename, position and context
- const SourceContext ctx = messageContext(msg);
-
- // Print the file name
- if (ctx.hasFile()) {
- os << t.bright() << ctx.filename << t.reset();
- }
-
- // Print line and column number
- if (ctx.hasLine()) {
- if (ctx.hasFile()) {
- os << ':';
- }
- os << t.bright() << ctx.startLine << t.reset();
- if (ctx.hasColumn()) {
- os << ':' << ctx.startColumn;
- }
- }
-
- // Print the optional seperator
- if (ctx.hasFile() || ctx.hasLine()) {
- os << ": ";
- }
-
- // Print the severity
- switch (msg.severity) {
- case Severity::DEBUG:
- break;
- case Severity::NOTE:
- os << t.color(Terminal::CYAN, true) << "note: ";
- break;
- case Severity::WARNING:
- os << t.color(Terminal::MAGENTA, true) << "warning: ";
- break;
- case Severity::ERROR:
- os << t.color(Terminal::RED, true) << "error: ";
- break;
- case Severity::FATAL_ERROR:
- os << t.color(Terminal::RED, true) << "fatal error: ";
- break;
- }
- os << t.reset();
-
- // Print the actual message
- os << msg.msg << std::endl;
-
- // Print the error message context if available
- if (ctx.hasText()) {
- // Iterate over each line in the text
- std::vector<std::string> lines = Utils::split(ctx.text, '\n');
-
- const size_t relLen = ctx.relLen ? ctx.relLen : 1;
- const size_t relPos = ctx.relPos;
- const size_t pstart = relPos;
- const size_t pend = relPos + relLen;
-
- size_t lstart = 0;
- size_t lend = 0;
- for (size_t n = 0; n < lines.size(); n++) {
- bool firstLine = n == 0;
- bool lastLine = n == lines.size() - 1;
-
- // Indicate truncation and indent non-first lines
- if (ctx.truncatedStart && firstLine) {
- os << "[...] ";
- }
- if (!firstLine) {
- os << "\t";
- }
-
- // Print the actual line
- os << lines[n];
-
- // Indicate truncation
- if (ctx.truncatedEnd && lastLine) {
- os << " [...]";
- }
- os << std::endl;
-
- // Repeat truncation or indendation space in the next line
- if (ctx.truncatedStart && firstLine) {
- os << " ";
- }
- if (!firstLine) {
- os << "\t";
- }
-
- // Print the position indicators
- lend = lastLine ? pend : lstart + lines[n].size();
- for (size_t i = lstart; i < lend; i++) {
- if (i >= pstart && i < pend) {
- os << t.color(Terminal::GREEN);
- for (; i < std::min(lend, pend); i++) {
- if (relLen == 1) {
- os << '^';
- } else {
- os << '~';
- }
- if (i < ctx.text.size() && ctx.text[i] == '\t') {
- os << '\t';
- }
- }
- os << t.reset();
- } else {
- if (i < ctx.text.size() && ctx.text[i] == '\t') {
- os << '\t';
- } else {
- os << ' ';
- }
- }
- }
- os << std::endl;
-
- lstart = lend;
- }
- }
-}
}