Skip to content

Commit b9ebe0c

Browse files
author
Denis Chapligin
authored
Merge pull request #5628 from wangyoucao577/feature/disable-debug-log-compile-time-control
Control release mode debug logging output by ENABLE_DEBUG_LOGGING option
2 parents cd4e6a1 + b7fa2c5 commit b9ebe0c

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- FIXED: treat `bicycle=use_sidepath` as no access on the tagged way. [#5622](https://github.com/Project-OSRM/osrm-backend/pull/5622)
2020
- Misc:
2121
- CHANGED: Reduce memory usage for raster source handling. [#5572](https://github.com/Project-OSRM/osrm-backend/pull/5572)
22+
- CHANGED: Add cmake option `ENABLE_DEBUG_LOGGING` to control whether output debug logging. [#3427](https://github.com/Project-OSRM/osrm-backend/issues/3427)
2223

2324
# 5.21.0
2425
- Changes from 5.20.0

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)
@@ -233,6 +234,7 @@ endif()
233234
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
234235
message(STATUS "Configuring debug mode flags")
235236
set(ENABLE_ASSERTIONS ON)
237+
set(ENABLE_DEBUG_LOGGING ON)
236238
endif()
237239

238240
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
@@ -737,6 +739,11 @@ if (ENABLE_ASSERTIONS)
737739
add_definitions(-DBOOST_ENABLE_ASSERT_HANDLER)
738740
endif()
739741

742+
if (ENABLE_DEBUG_LOGGING)
743+
message(STATUS "Enabling debug logging")
744+
add_definitions(-DENABLE_DEBUG_LOGGING)
745+
endif()
746+
740747
# Add RPATH info to executables so that when they are run after being installed
741748
# (i.e., from /usr/local/bin/) the linker can find library dependencies. For
742749
# 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)