feat(logging): add colored file:line numbers to JLOG macro

- Add LOG_LINE_NUMBERS CMake option (ON for Debug, OFF for Release)
- Implement constexpr path stripping using SOURCE_ROOT_PATH
- Add smart TTY detection with NO_COLOR/FORCE_COLOR support
- Extend Journal::ScopedStream with file/line constructor
- Update JLOG macro to conditionally include source location
- Maintain backward compatibility when disabled
This commit is contained in:
Nicholas Dudfield
2025-07-25 17:46:50 +07:00
parent 849d447a20
commit 20344ab999
3 changed files with 138 additions and 1 deletions

View File

@@ -33,6 +33,24 @@ if(Git_FOUND)
endif()
endif() #git
# make SOURCE_ROOT_PATH define available for logging
set(SOURCE_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/")
add_definitions(-DSOURCE_ROOT_PATH="${SOURCE_ROOT_PATH}")
# LOG_LINE_NUMBERS option - default to ON for Debug builds, OFF for Release
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
option(LOG_LINE_NUMBERS "Include file and line numbers in log messages" ON)
else()
option(LOG_LINE_NUMBERS "Include file and line numbers in log messages" OFF)
endif()
if(LOG_LINE_NUMBERS)
add_definitions(-DLOG_LINE_NUMBERS=1)
message(STATUS "Log line numbers enabled")
else()
message(STATUS "Log line numbers disabled")
endif()
if(thread_safety_analysis)
add_compile_options(-Wthread-safety -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -DRIPPLE_ENABLE_THREAD_SAFETY_ANNOTATIONS)
add_compile_options("-stdlib=libc++")