From eef0043e76c758efd6a9c3d628d6e3a655031f21 Mon Sep 17 00:00:00 2001 From: Denys Date: Thu, 5 Dec 2024 22:47:09 +0200 Subject: [PATCH] Remove path prefix in RNP_LOG --- CMakeLists.txt | 4 ++++ src/lib/logging.h | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db78e5fd8..a5412cd1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,10 @@ set_property(CACHE ENABLE_DOC PROPERTY STRINGS ${TRISTATE_VALUES}) # so we can use our bundled finders set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules") +# add source path prefix length to be able to crop it in logs +string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE) +add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}") + # required modules include(CTest) include(FetchContent) diff --git a/src/lib/logging.h b/src/lib/logging.h index bebb7bc46..5f5f46835 100644 --- a/src/lib/logging.h +++ b/src/lib/logging.h @@ -58,13 +58,15 @@ class LogStop { }; } // namespace rnp -#define RNP_LOG_FD(fd, ...) \ - do { \ - if (!rnp_log_switch()) \ - break; \ - (void) fprintf((fd), "[%s() %s:%d] ", __func__, __FILE__, __LINE__); \ - (void) fprintf((fd), __VA_ARGS__); \ - (void) fprintf((fd), "\n"); \ +#define __SOURCE_PATH_FILE__ (__FILE__ + SOURCE_PATH_SIZE + 3 /* remove "src" */) + +#define RNP_LOG_FD(fd, ...) \ + do { \ + if (!rnp_log_switch()) \ + break; \ + (void) fprintf((fd), "[%s() %s:%d] ", __func__, __SOURCE_PATH_FILE__, __LINE__); \ + (void) fprintf((fd), __VA_ARGS__); \ + (void) fprintf((fd), "\n"); \ } while (0) #define RNP_LOG(...) RNP_LOG_FD(stderr, __VA_ARGS__)