Made output and error streams members of the logger.

This commit is contained in:
Patrick Lühne 2016-06-14 15:56:35 +02:00
parent b599670572
commit febef4bed4
2 changed files with 24 additions and 10 deletions

View File

@ -3,6 +3,7 @@
#include <string>
#include <plasp/utils/LogStream.h>
#include <plasp/utils/Parser.h>
#include <plasp/utils/ParserException.h>
@ -36,6 +37,9 @@ class Logger
Logger(Logger &&other);
Logger &operator=(Logger &&other);
LogStream<StandardStream::Out> &outputStream();
LogStream<StandardStream::Err> &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<StandardStream::Out> m_outputStream;
LogStream<StandardStream::Err> m_errorStream;
WarningLevel m_warningLevel;
};

View File

@ -1,7 +1,6 @@
#include <plasp/utils/Logger.h>
#include <plasp/utils/Formatting.h>
#include <plasp/utils/LogStream.h>
namespace plasp
{
@ -55,6 +54,20 @@ Logger &Logger::operator=(Logger &&other)
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream<StandardStream::Out> &Logger::outputStream()
{
return m_outputStream;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream<StandardStream::Err> &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<StandardStream::Err> 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<StandardStream::Err> 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<StandardStream::Err> stream;
stream
m_errorStream
<< Format(Color::White, FontWeight::Bold) << coordinate.sectionName << ":"
<< std::to_string(coordinate.row) + ":" + std::to_string(coordinate.column) << ":"
<< ResetFormat() << " "