Skip to content

Commit

Permalink
logging: Don't print absolute path to source file. Fixes #548
Browse files Browse the repository at this point in the history
  • Loading branch information
xor-gate committed Feb 14, 2017
1 parent 88c6162 commit 2c0ab7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
include(CTest)
endif()

# fixup __FILE__ absolute paths in logging module
# see: https://cmake.org/pipermail/cmake-developers/2015-January/024202.html
string(LENGTH "${CMAKE_SOURCE_DIR}/" CMAKE_SOURCE_DIR_LENGTH)
add_definitions(-DCMAKE_SOURCE_DIR_LENGTH=${CMAKE_SOURCE_DIR_LENGTH})

set(STLINK_HEADERS
include/stlink.h
include/stlink/usb.h
Expand Down
15 changes: 10 additions & 5 deletions include/stlink/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@ enum ugly_loglevel {
int ugly_init(int maximum_threshold);
int ugly_log(int level, const char *tag, const char *format, ...);

#ifndef CMAKE_SOURCE_DIR_LENGTH
#define CMAKE_SOURCE_DIR_LENGTH 0
#endif
#define UGLY_LOG_FILE (__FILE__+CMAKE_SOURCE_DIR_LENGTH)

/** @todo we need to write this in a more generic way, for now this should compile
on visual studio (See http://stackoverflow.com/a/8673872/1836746) */
#define DLOG_HELPER(format, ...) ugly_log(UDEBUG, __FILE__, format, __VA_ARGS__)
#define DLOG_HELPER(format, ...) ugly_log(UDEBUG, UGLY_LOG_FILE, format, __VA_ARGS__)
#define DLOG(...) DLOG_HELPER(__VA_ARGS__, "")
#define ILOG_HELPER(format, ...) ugly_log(UINFO, __FILE__, format, __VA_ARGS__)
#define ILOG_HELPER(format, ...) ugly_log(UINFO, UGLY_LOG_FILE, format, __VA_ARGS__)
#define ILOG(...) ILOG_HELPER(__VA_ARGS__, "")
#define WLOG_HELPER(format, ...) ugly_log(UWARN, __FILE__, format, __VA_ARGS__)
#define WLOG_HELPER(format, ...) ugly_log(UWARN, UGLY_LOG_FILE, format, __VA_ARGS__)
#define WLOG(...) WLOG_HELPER(__VA_ARGS__, "")
#define ELOG_HELPER(format, ...) ugly_log(UERROR, __FILE__, format, __VA_ARGS__)
#define ELOG_HELPER(format, ...) ugly_log(UERROR, UGLY_LOG_FILE, format, __VA_ARGS__)
#define ELOG(...) ELOG_HELPER(__VA_ARGS__, "")
#define fatal_helper(format, ...) ugly_log(UFATAL, __FILE__, format, __VA_ARGS__)
#define fatal_helper(format, ...) ugly_log(UFATAL, UGLY_LOG_FILE, format, __VA_ARGS__)
#define fatal(...) fatal_helper(__VA_ARGS__, "")

#ifdef __cplusplus
Expand Down

0 comments on commit 2c0ab7f

Please sign in to comment.