From febef4bed4efc1b3c9dc801e1cc1e1abebcd0253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 14 Jun 2016 15:56:35 +0200 Subject: [PATCH] Made output and error streams members of the logger. --- include/plasp/utils/Logger.h | 7 +++++++ src/plasp/utils/Logger.cpp | 27 +++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/plasp/utils/Logger.h b/include/plasp/utils/Logger.h index d917dea..732a183 100644 --- a/include/plasp/utils/Logger.h +++ b/include/plasp/utils/Logger.h @@ -3,6 +3,7 @@ #include +#include #include #include @@ -36,6 +37,9 @@ class Logger Logger(Logger &&other); Logger &operator=(Logger &&other); + LogStream &outputStream(); + LogStream &errorStream(); + void setWarningLevel(WarningLevel warningLevel); void logError(const std::string &message); @@ -43,6 +47,9 @@ class Logger void logWarning(const Parser &parser, const std::string &message); private: + LogStream m_outputStream; + LogStream m_errorStream; + WarningLevel m_warningLevel; }; diff --git a/src/plasp/utils/Logger.cpp b/src/plasp/utils/Logger.cpp index 5e4cfac..af42817 100644 --- a/src/plasp/utils/Logger.cpp +++ b/src/plasp/utils/Logger.cpp @@ -1,7 +1,6 @@ #include #include -#include namespace plasp { @@ -55,6 +54,20 @@ Logger &Logger::operator=(Logger &&other) //////////////////////////////////////////////////////////////////////////////////////////////////// +LogStream &Logger::outputStream() +{ + return m_outputStream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +LogStream &Logger::errorStream() +{ + return m_errorStream; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + void Logger::setWarningLevel(WarningLevel warningLevel) { m_warningLevel = warningLevel; @@ -64,9 +77,7 @@ void Logger::setWarningLevel(WarningLevel warningLevel) void Logger::logError(const std::string &message) { - LogStream stream; - - stream + m_errorStream << Format(Color::Red, FontWeight::Bold) << "error:" << ResetFormat() << " " << Format(Color::White, FontWeight::Bold) << message @@ -77,9 +88,7 @@ void Logger::logError(const std::string &message) void Logger::logError(const Parser::Coordinate &coordinate, const std::string &message) { - LogStream stream; - - stream + m_errorStream << Format(Color::White, FontWeight::Bold) << coordinate.sectionName << ":" << std::to_string(coordinate.row) + ":" + std::to_string(coordinate.column) << ":" << ResetFormat() << " " @@ -101,9 +110,7 @@ void Logger::logWarning(const Parser &parser, const std::string &message) const auto coordinate = parser.coordinate(); - LogStream stream; - - stream + m_errorStream << Format(Color::White, FontWeight::Bold) << coordinate.sectionName << ":" << std::to_string(coordinate.row) + ":" + std::to_string(coordinate.column) << ":" << ResetFormat() << " "