Skip to content

Commit 0f03f07

Browse files
committed
logging: add CMake flag to disable colorful logging
Signed-off-by: Torbjörn Klatt <[email protected]>
1 parent bf65260 commit 0f03f07

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CMAKE_DEPENDENT_OPTION(pfasst_INSTALL_EXAMPLES "Install example programs." ON
2020
"pfasst_BUILD_EXAMPLES" OFF)
2121
option(pfasst_BUILD_TESTS "Build test suite for PFASST." ON )
2222
option(pfasst_WITH_MPI "Build with MPI enabled." ON )
23+
option(pfasst_WITH_COLOR "Enable colorful logging output." ON )
2324
option(pfasst_WITH_GCC_PROF "Enable excessive debugging & profiling output with GCC." OFF)
2425
option(pfasst_DEFAULT_RAND_SEED "Using a hardcoded random seed" ON )
2526

@@ -43,6 +44,10 @@ if(pfasst_DEFAULT_RAND_SEED)
4344
set(pfasst_RANDOM_SEED "42")
4445
endif()
4546

47+
if(NOT ${pfasst_WITH_COLOR})
48+
add_definitions(-DNO_COLOR)
49+
endif()
50+
4651
# Check for C++11 support
4752
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
4853
check_cxx_compiler_flag(-std=c++11 HAVE_STD11)
@@ -113,6 +118,10 @@ add_feature_info(MPI
113118
pfasst_WITH_MPI
114119
"build with MPI"
115120
)
121+
add_feature_info(COLOR
122+
pfasst_WITH_COLOR
123+
"colorful logging"
124+
)
116125
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
117126
add_feature_info(Profiling
118127
pfasst_WITH_GCC_PROF

include/pfasst/logging.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ struct OUT
5252
static const string reset;
5353
};
5454

55+
#ifdef NO_COLOR
56+
const string OUT::black = "";
57+
const string OUT::red = "";
58+
const string OUT::green = "";
59+
const string OUT::yellow = "";
60+
const string OUT::blue = "";
61+
const string OUT::magenta = "";
62+
const string OUT::cyan = "";
63+
const string OUT::white = "";
64+
65+
const string OUT::bold = "";
66+
const string OUT::underline = "";
67+
68+
const string OUT::reset = "";
69+
#else
5570
const string OUT::black = "\033[30m";
5671
const string OUT::red = "\033[31m";
5772
const string OUT::green = "\033[32m";
@@ -65,7 +80,7 @@ const string OUT::bold = "\033[1m";
6580
const string OUT::underline = "\033[4m";
6681

6782
const string OUT::reset = "\033[0m";
68-
83+
#endif
6984

7085
// enable easy logging of STL containers
7186
#define ELPP_STL_LOGGING
@@ -325,7 +340,11 @@ namespace pfasst
325340
{
326341
el::Loggers::addFlag(el::LoggingFlag::LogDetailedCrashReason);
327342
el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog);
343+
#ifdef NO_COLOR
344+
el::Loggers::removeFlag(el::LoggingFlag::ColoredTerminalOutput);
345+
#else
328346
el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput);
347+
#endif
329348
el::Loggers::addFlag(el::LoggingFlag::MultiLoggerSupport);
330349
el::Loggers::addFlag(el::LoggingFlag::CreateLoggerAutomatically);
331350
}

0 commit comments

Comments
 (0)