Skip to content

Commit

Permalink
Remove path prefix in RNP_LOG
Browse files Browse the repository at this point in the history
  • Loading branch information
desvxx committed Dec 5, 2024
1 parent ddcbaa9 commit eef0043
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions src/lib/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit eef0043

Please sign in to comment.