Skip to content

Commit

Permalink
Support full filenames in logs.
Browse files Browse the repository at this point in the history
This is helpful for doing cut and paste of filenames when opening.
Also fixed couple of macro parentheses.
  • Loading branch information
spinorx committed Oct 11, 2017
1 parent 833b22d commit fd4b751
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/g3log/g3log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/logmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fd4b751

Please sign in to comment.