Support full filenames in logs. (#226)

This is helpful for doing cut and paste of filenames when opening.
Also fixed couple of macro parentheses.
This commit is contained in:
spinorx 2017-10-11 11:59:46 -07:00 committed by Kjell Hedström
parent 833b22d23b
commit 28105e08d7
3 changed files with 17 additions and 2 deletions

View File

@ -72,6 +72,17 @@ ELSE()
ENDIF(USE_G3_DYNAMIC_MAX_MESSAGE_SIZE)
# G3LOG_FULL_FILENAME logs full file name instead of short filename. This makes it
# easier to copy filenames to open them without needing to search.
option (G3_LOG_FULL_FILENAME "Log full filename" OFF)
IF(G3_LOG_FULL_FILENAME)
LIST(APPEND G3_DEFINITIONS G3_LOG_FULL_FILENAME)
message( STATUS "-DG3_LOG_FULL_FILENAME=ON\t\tShowing full filenames with logs")
ELSE()
message( STATUS "-DG3_LOG_FULL_FILENAME=OFF")
ENDIF(G3_LOG_FULL_FILENAME)
# -DENABLE_FATAL_SIGNALHANDLING=ON : defualt change the
# By default fatal signal handling is enabled. You can disable it with this option
# enumerated in src/stacktrace_windows.cpp

View File

@ -150,7 +150,7 @@ namespace g3 {
// 'Conditional' stream log
#define LOG_IF(level, boolean_expression) \
if(true == boolean_expression) \
if(true == (boolean_expression)) \
if(g3::logLevel(level)) INTERNAL_LOG_MESSAGE(level).stream()
// 'Design By Contract' stream API. For Broken Contracts:
@ -213,7 +213,7 @@ And here is possible output
// Conditional log printf syntax
#define LOGF_IF(level,boolean_expression, printf_like_message, ...) \
if(true == boolean_expression) \
if(true == (boolean_expression)) \
if(g3::logLevel(level)) INTERNAL_LOG_MESSAGE(level).capturef(printf_like_message, ##__VA_ARGS__)
// Design By Contract, printf-like API syntax with variadic input parameters.

View File

@ -127,7 +127,11 @@ namespace g3 {
const std::string& function, const LEVELS& level)
: _timestamp(std::chrono::high_resolution_clock::now())
, _call_thread_id(std::this_thread::get_id())
#if defined(G3_LOG_FULL_FILENAME)
, _file(file)
#else
, _file(splitFileName(file))
#endif
, _file_path(file)
, _line(line)
, _function(function)