Only use color coding for simple log setup if terminal.

Note that isatty() might need to be replaced by isatty_() for Windows.
This commit is contained in:
Atgeirr Flø Rasmussen
2017-03-17 08:46:50 +01:00
parent 726496c0b6
commit 7462cc4b96
+9 -1
View File
@@ -21,9 +21,17 @@
#include <opm/common/OpmLog/Logger.hpp>
#include <opm/common/OpmLog/StreamLog.hpp>
#include <iostream>
#include <unistd.h> // For isatty() etc.
namespace Opm {
namespace {
bool stdoutIsTerminal()
{
return isatty(fileno(stdout));
}
}
std::shared_ptr<Logger> OpmLog::getLogger() {
if (!m_logger)
@@ -183,7 +191,7 @@ namespace Opm {
std::shared_ptr<StreamLog> streamLog = std::make_shared<StreamLog>(std::cout, Log::DefaultMessageTypes);
OpmLog::addBackend( "SimpleDefaultLog", streamLog);
streamLog->setMessageLimiter(std::make_shared<MessageLimiter>(message_limit));
streamLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(use_prefix, use_color_coding));
streamLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(use_prefix, use_color_coding && stdoutIsTerminal()));
}
/******************************************************************/