diff --git a/Options.cmake b/Options.cmake index 9a0432d..5396bc9 100644 --- a/Options.cmake +++ b/Options.cmake @@ -14,6 +14,8 @@ # to the auto generated file src/g3log/generated_definitions.hpp # add_definitions(-DG3_DYNAMIC_LOGGING) # add_definitions(-DCHANGE_G3LOG_DEBUG_TO_DBUG) +# add_definitions(-DWINDOWS_FUNCSIG) +# add_definitions(-DPRETTY_FUNCTION) # add_definitions(-DDISABLE_FATAL_SIGNALHANDLING) # add_definitions(-DDISABLE_VECTORED_EXCEPTIONHANDLING) # add_definitions(-DDEBUG_BREAK_AT_FATAL_SIGNAL) @@ -61,6 +63,31 @@ ELSE() ENDIF(CHANGE_G3LOG_DEBUG_TO_DBUG) +# -DWINDOWS_USE_FUNCSIG=ON : (Default OFF) Override the use of __FUNCTION__ for Windows platform and instead use __FUNCSIG__ +option (WINDOWS_FUNCSIG + "Windows __FUNCSIG__ to expand `Function` location of the LOG call instead of the default __FUNCTION__" OFF) +IF(WINDOWS_FUNCSIG) + LIST(APPEND G3_DEFINITIONS WINDOWS_FUNCSIG) + message( STATUS "-DWINDOWS_FUNCSIG=ON\t\t__SIGFUNC__ is used instead of the default __FUNCTION__ for LOG call locations" ) +ELSE() + message( STATUS "-DWINDOWS_FUNCSIG=OFF") +ENDIF(WINDOWS_FUNCSIG) + + +# -DPRETTY_FUNCTION=ON : (Default OFF) Override the use of __FUNCTION__ for Windows platform and instead use __FUNCSIG__ +# NOTE: heavy templated integrations such as boost log calls that shows the function name can cause function name expansion +# to "spam" the LOG output with the now visible template arguments. +option (PRETTY_FUNCTION + "Windows __PRETTY_FUNCTION__ to expand `Function` location of the LOG call instead of the default __FUNCTION__" OFF) +IF(PRETTY_FUNCTION) + LIST(APPEND G3_DEFINITIONS PRETTY_FUNCTION) + message( STATUS "-DPRETTY_FUNCTION=ON\t\t__PRETTY_FUNCTION__ is used instead of the default __FUNCTION__ for LOG call locations" ) +ELSE() + message( STATUS "-DPRETTY_FUNCTION=OFF") +ENDIF(PRETTY_FUNCTION) + + + # -DG3_DYNAMIC_MAX_MESSAGE_SIZE : use dynamic memory for final_message in logcapture.cpp option (USE_G3_DYNAMIC_MAX_MESSAGE_SIZE "Use dynamic memory for message buffer during log capturing" OFF) diff --git a/appveyor.yml b/appveyor.yml index 8421b59..19a00e2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,7 +24,7 @@ before_build: - cd build build_script: - - cmake -G "Visual Studio 15 2017 Win64" -DADD_G3LOG_UNIT_TEST=ON -DUSE_DYNAMIC_LOGGING_LEVELS=ON -DCHANGE_G3LOG_DEBUG_TO_DBUG=ON -DCMAKE_INSTALL_PREFIX=c:\g3log .. + - cmake -G "Visual Studio 15 2017 Win64" -DADD_G3LOG_UNIT_TEST=ON -DWINDOWS_FUNCSIG=ON -DUSE_DYNAMIC_LOGGING_LEVELS=ON -DCHANGE_G3LOG_DEBUG_TO_DBUG=ON -DCMAKE_INSTALL_PREFIX=c:\g3log .. - cmake --build . --config Release --target install # scripts to run after build diff --git a/docs/building.md b/docs/building.md index c29e6ac..732676a 100644 --- a/docs/building.md +++ b/docs/building.md @@ -47,6 +47,21 @@ ADD_G3LOG_UNIT_TEST:BOOL=OFF // By default DEBUG is the debugging level CHANGE_G3LOG_DEBUG_TO_DBUG:BOOL=OFF + +// Windows only: Use __FUNCSIG__ instead of the default __FUNCTION__ +// to show LOG function location +// WARNING: using this in heavily templated code, like boost can expand +// the function name into massive size +WINDOWS_FUNCSIG:BOOL=OFF + + +// gcc/clang only: Use __PRETTY_FUNCTION__ instead of the default __FUNCTION__ +// to show LOG function location +// WARNING: using this in heavily templated code, like boost can expand +// the function name into massive size +PRETTY_FUNCTION:BOOL=OFF + + // Specifies the build type on single-configuration generators. // Possible values are empty, Debug, Release, RelWithDebInfo, MinSizeRel, … CMAKE_BUILD_TYPE:STRING= diff --git a/scripts/buildAndRunTests.sh b/scripts/buildAndRunTests.sh index 90525c3..62875fc 100755 --- a/scripts/buildAndRunTests.sh +++ b/scripts/buildAndRunTests.sh @@ -6,7 +6,7 @@ set -x mkdir -p build_travis cd build_travis -cmake -DADD_G3LOG_BENCH_PERFORMANCE=ON -DADD_G3LOG_UNIT_TEST=ON -DCMAKE_INSTALL_PREFIX=./install -DCPACK_PACKAGING_INSTALL_PREFIX=/opt/g3log .. +cmake -DADD_G3LOG_BENCH_PERFORMANCE=ON -DPRETTY_FUNCTION=ON -DADD_G3LOG_UNIT_TEST=ON -DCMAKE_INSTALL_PREFIX=./install -DCPACK_PACKAGING_INSTALL_PREFIX=/opt/g3log .. cmake --build . --target install if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then diff --git a/src/g3log/g3log.hpp b/src/g3log/g3log.hpp index 87b9d7a..1a2dc81 100644 --- a/src/g3log/g3log.hpp +++ b/src/g3log/g3log.hpp @@ -29,12 +29,11 @@ #include #include - -#if defined(__GNUC__) // GCC extension compatible -#define G3LOG_PRETTY_FUNCTION __PRETTY_FUNCTION__ -#elif defined(_MSC_VER) // Microsoft +#if defined(_MSC_VER) && (defined(WINDOWS_FUNCSIG)) // Microsoft #define G3LOG_PRETTY_FUNCTION __FUNCSIG__ -#else // __func__ is fallback to c99 / c++11, where that doesn't matter so __FUNCTION__ is the choice +#elif defined(__GNUC__) && defined(PRETTY_FUNCTION) // GCC compatible +#define G3LOG_PRETTY_FUNCTION __PRETTY_FUNCTION__ +#else #define G3LOG_PRETTY_FUNCTION __FUNCTION__ #endif