From 1ada4660817139c436e9afe13e8360d2458dc5c3 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Mon, 9 Dec 2019 17:53:28 +0800 Subject: [PATCH 1/5] chore: remove compile time debug log control --- src/util/log.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/util/log.cpp b/src/util/log.cpp index 602012bd996..f402efe9457 100644 --- a/src/util/log.cpp +++ b/src/util/log.cpp @@ -16,9 +16,7 @@ namespace static const char COL_RESET[]{"\x1b[0m"}; static const char RED[]{"\x1b[31m"}; static const char YELLOW[]{"\x1b[33m"}; -#ifndef NDEBUG static const char MAGENTA[]{"\x1b[35m"}; -#endif // static const char GREEN[] { "\x1b[32m"}; // static const char BLUE[] { "\x1b[34m"}; // static const char CYAN[] { "\x1b[36m"}; @@ -80,9 +78,7 @@ Log::Log(LogLevel level_, std::ostream &ostream) : level(level_), stream(ostream stream << (is_terminal ? RED : "") << "[error] "; break; case logDEBUG: -#ifndef NDEBUG stream << (is_terminal ? MAGENTA : "") << "[debug] "; -#endif break; default: // logINFO: stream << "[info] "; @@ -126,9 +122,6 @@ Log::~Log() std::cerr << std::endl; break; case logDEBUG: -#ifdef NDEBUG - break; -#endif case logINFO: default: std::cout << buffer.str(); From 11b0a2e02a9e14d560cb609d9df7e3666c088cd0 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Mon, 9 Dec 2019 23:19:37 +0800 Subject: [PATCH 2/5] docs: update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8bb0f72da3..97779d9d5a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - FIXED: treat `bicycle=use_sidepath` as no access on the tagged way. [#5622](https://github.com/Project-OSRM/osrm-backend/pull/5622) - Misc: - CHANGED: Reduce memory usage for raster source handling. [#5572](https://github.com/Project-OSRM/osrm-backend/pull/5572) + - CHANGED: Remove compile time debug log control. [#3427](https://github.com/Project-OSRM/osrm-backend/issues/3427) # 5.21.0 - Changes from 5.20.0 From 36d34073da930a70168e4f4bcd135b7ad667056c Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 29 Jul 2020 05:10:12 +0000 Subject: [PATCH 3/5] Revert "chore: remove compile time debug log control" This reverts commit 1ada4660817139c436e9afe13e8360d2458dc5c3. --- src/util/log.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util/log.cpp b/src/util/log.cpp index f402efe9457..602012bd996 100644 --- a/src/util/log.cpp +++ b/src/util/log.cpp @@ -16,7 +16,9 @@ namespace static const char COL_RESET[]{"\x1b[0m"}; static const char RED[]{"\x1b[31m"}; static const char YELLOW[]{"\x1b[33m"}; +#ifndef NDEBUG static const char MAGENTA[]{"\x1b[35m"}; +#endif // static const char GREEN[] { "\x1b[32m"}; // static const char BLUE[] { "\x1b[34m"}; // static const char CYAN[] { "\x1b[36m"}; @@ -78,7 +80,9 @@ Log::Log(LogLevel level_, std::ostream &ostream) : level(level_), stream(ostream stream << (is_terminal ? RED : "") << "[error] "; break; case logDEBUG: +#ifndef NDEBUG stream << (is_terminal ? MAGENTA : "") << "[debug] "; +#endif break; default: // logINFO: stream << "[info] "; @@ -122,6 +126,9 @@ Log::~Log() std::cerr << std::endl; break; case logDEBUG: +#ifdef NDEBUG + break; +#endif case logINFO: default: std::cout << buffer.str(); From 106082f6f8d214aa2783b57e0705ed4426340dbe Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 29 Jul 2020 06:00:47 +0000 Subject: [PATCH 4/5] feat: add ENABLE_DEBUG_LOGGING option to control debug logging output --- CMakeLists.txt | 7 +++++++ src/util/log.cpp | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b1aaf3ab7a..db52c58a61f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ option(ENABLE_CCACHE "Speed up incremental rebuilds via ccache" ON) option(BUILD_TOOLS "Build OSRM tools" OFF) option(BUILD_PACKAGE "Build OSRM package" OFF) option(ENABLE_ASSERTIONS "Use assertions in release mode" OFF) +option(ENABLE_DEBUG_LOGGING "Use debug logging in release mode" OFF) option(ENABLE_COVERAGE "Build with coverage instrumentalisation" OFF) option(ENABLE_SANITIZER "Use memory sanitizer for Debug build" OFF) option(ENABLE_STXXL "Use STXXL library" OFF) @@ -227,6 +228,7 @@ endif() if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) message(STATUS "Configuring debug mode flags") set(ENABLE_ASSERTIONS ON) + set(ENABLE_DEBUG_LOGGING ON) endif() if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") @@ -734,6 +736,11 @@ if (ENABLE_ASSERTIONS) add_definitions(-DBOOST_ENABLE_ASSERT_HANDLER) endif() +if (ENABLE_DEBUG_LOGGING) + message(STATUS "Enabling debug logging") + add_definitions(-DENABLE_DEBUG_LOGGING) +endif() + # Add RPATH info to executables so that when they are run after being installed # (i.e., from /usr/local/bin/) the linker can find library dependencies. For # more info see http://www.cmake.org/Wiki/CMake_RPATH_handling diff --git a/src/util/log.cpp b/src/util/log.cpp index 602012bd996..0d9a0681337 100644 --- a/src/util/log.cpp +++ b/src/util/log.cpp @@ -16,7 +16,7 @@ namespace static const char COL_RESET[]{"\x1b[0m"}; static const char RED[]{"\x1b[31m"}; static const char YELLOW[]{"\x1b[33m"}; -#ifndef NDEBUG +#ifdef ENABLE_DEBUG_LOGGING static const char MAGENTA[]{"\x1b[35m"}; #endif // static const char GREEN[] { "\x1b[32m"}; @@ -80,7 +80,7 @@ Log::Log(LogLevel level_, std::ostream &ostream) : level(level_), stream(ostream stream << (is_terminal ? RED : "") << "[error] "; break; case logDEBUG: -#ifndef NDEBUG +#ifdef ENABLE_DEBUG_LOGGING stream << (is_terminal ? MAGENTA : "") << "[debug] "; #endif break; @@ -126,7 +126,7 @@ Log::~Log() std::cerr << std::endl; break; case logDEBUG: -#ifdef NDEBUG +#ifndef ENABLE_DEBUG_LOGGING break; #endif case logINFO: From b7fa2c5981b658c75663decb458b209f7636a6ad Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Wed, 29 Jul 2020 06:02:19 +0000 Subject: [PATCH 5/5] docs: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97779d9d5a2..992f8b4ca2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ - FIXED: treat `bicycle=use_sidepath` as no access on the tagged way. [#5622](https://github.com/Project-OSRM/osrm-backend/pull/5622) - Misc: - CHANGED: Reduce memory usage for raster source handling. [#5572](https://github.com/Project-OSRM/osrm-backend/pull/5572) - - CHANGED: Remove compile time debug log control. [#3427](https://github.com/Project-OSRM/osrm-backend/issues/3427) + - CHANGED: Add cmake option `ENABLE_DEBUG_LOGGING` to control whether output debug logging. [#3427](https://github.com/Project-OSRM/osrm-backend/issues/3427) # 5.21.0 - Changes from 5.20.0