Skip to content

Commit 106082f

Browse files
committed
feat: add ENABLE_DEBUG_LOGGING option to control debug logging output
1 parent 36d3407 commit 106082f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ option(ENABLE_CCACHE "Speed up incremental rebuilds via ccache" ON)
2323
option(BUILD_TOOLS "Build OSRM tools" OFF)
2424
option(BUILD_PACKAGE "Build OSRM package" OFF)
2525
option(ENABLE_ASSERTIONS "Use assertions in release mode" OFF)
26+
option(ENABLE_DEBUG_LOGGING "Use debug logging in release mode" OFF)
2627
option(ENABLE_COVERAGE "Build with coverage instrumentalisation" OFF)
2728
option(ENABLE_SANITIZER "Use memory sanitizer for Debug build" OFF)
2829
option(ENABLE_STXXL "Use STXXL library" OFF)
@@ -227,6 +228,7 @@ endif()
227228
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
228229
message(STATUS "Configuring debug mode flags")
229230
set(ENABLE_ASSERTIONS ON)
231+
set(ENABLE_DEBUG_LOGGING ON)
230232
endif()
231233

232234
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
@@ -734,6 +736,11 @@ if (ENABLE_ASSERTIONS)
734736
add_definitions(-DBOOST_ENABLE_ASSERT_HANDLER)
735737
endif()
736738

739+
if (ENABLE_DEBUG_LOGGING)
740+
message(STATUS "Enabling debug logging")
741+
add_definitions(-DENABLE_DEBUG_LOGGING)
742+
endif()
743+
737744
# Add RPATH info to executables so that when they are run after being installed
738745
# (i.e., from /usr/local/bin/) the linker can find library dependencies. For
739746
# more info see http://www.cmake.org/Wiki/CMake_RPATH_handling

src/util/log.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace
1616
static const char COL_RESET[]{"\x1b[0m"};
1717
static const char RED[]{"\x1b[31m"};
1818
static const char YELLOW[]{"\x1b[33m"};
19-
#ifndef NDEBUG
19+
#ifdef ENABLE_DEBUG_LOGGING
2020
static const char MAGENTA[]{"\x1b[35m"};
2121
#endif
2222
// static const char GREEN[] { "\x1b[32m"};
@@ -80,7 +80,7 @@ Log::Log(LogLevel level_, std::ostream &ostream) : level(level_), stream(ostream
8080
stream << (is_terminal ? RED : "") << "[error] ";
8181
break;
8282
case logDEBUG:
83-
#ifndef NDEBUG
83+
#ifdef ENABLE_DEBUG_LOGGING
8484
stream << (is_terminal ? MAGENTA : "") << "[debug] ";
8585
#endif
8686
break;
@@ -126,7 +126,7 @@ Log::~Log()
126126
std::cerr << std::endl;
127127
break;
128128
case logDEBUG:
129-
#ifdef NDEBUG
129+
#ifndef ENABLE_DEBUG_LOGGING
130130
break;
131131
#endif
132132
case logINFO:

0 commit comments

Comments
 (0)