Skip to content

Commit 7c27a65

Browse files
feat: add wheel_utils module with logging functionality
1 parent 94a6f68 commit 7c27a65

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

wheel_utils/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
add_library(wheel_utils INTERFACE)
2+
3+
target_sources(
4+
wheel_utils
5+
INTERFACE
6+
FILE_SET HEADERS
7+
BASE_DIRS include
8+
FILES
9+
include/logging.hxx
10+
)
11+
12+
target_include_directories(
13+
wheel_utils
14+
INTERFACE
15+
${CMAKE_CURRENT_SOURCE_DIR}/include
16+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#if !defined(__WHEEL_UTILS_CONFIG_HXX)
2+
#define __WHEEL_UTILS_CONFIG_HXX
3+
4+
#define WHEEL_UTILS_NAMESPACE namespace wheel_utils {
5+
#define WHEEL_UTILS_END_NAMESPACE }
6+
7+
#endif // __WHEEL_UTILS_CONFIG_HXX
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#if !defined(LOGGING_HXX)
2+
#define LOGGING_HXX
3+
#include "__wheel_utils_config.hxx"
4+
5+
#include <iostream>
6+
#include <format>
7+
#include <cstring>
8+
9+
WHEEL_UTILS_NAMESPACE
10+
11+
#if defined(WHEEL_DEBUG)
12+
#if defined(_MSVC_LANG)
13+
#define CURRENT_CPP_VERSION _MSVC_LANG
14+
15+
#else
16+
#define CURRENT_CPP_VERSION __cplusplus
17+
#endif
18+
19+
#if CURRENT_CPP_VERSION >= 202002L
20+
#if defined(_WIN32)
21+
#define WHEEL_BASE_NAME(path) ((std::strrchr(path, '\\')) ? std::strrchr(path, '\\') + 1 : path)
22+
23+
#else
24+
#define WHEEL_BASE_NAME(path) ((std::strrchr(path, '/')) ? std::strrchr(path, '/') + 1 : path)
25+
26+
#endif
27+
28+
#define DEBUG_PRINT(msg) \
29+
do { \
30+
const auto fmt = std::format("[DEBUG] [{}:{}] {}", __LINE__, WHEEL_BASE_NAME(__FILE__), msg);\
31+
std::cout << fmt << "\n";\
32+
} while(0)
33+
34+
#else
35+
#define DEBUG_PRINT(msg) ((void)0)
36+
#endif
37+
38+
#else
39+
#define DEBUG_PRINT(msg) ((void)0)
40+
#endif
41+
42+
WHEEL_UTILS_END_NAMESPACE
43+
44+
#endif // LOGGING_HXX

0 commit comments

Comments
 (0)