一个现代、强大的C++23日志输出库
document »
bug report
·
feature request
GitHub stars GitHub forks License C++23 Build Status Benchmark Clang Support GCC Support MSVC Support
debug_macro 是一个现代化的C++23日志输出库,专为开发者提供直观、强大的调试输出工具。受Rust dbg!() 宏启发,致力于简化日志记录和调试过程。
- 🌈 彩色日志输出
- 🔧 跨平台支持 (Unix/Windows)
- 📦
Header-only库,零依赖 - 🖥️ 支持几乎所有C++可打印类型
- 🛠️ 编译器兼容性 (Clang/GCC/MSVC)
- 🚀
C++23标准支持 - 💡 智能类型推导和格式化输出
C++23兼容编译器- 无额外依赖
#include "debug_macro.hpp"
# CMakeLists.txt cmake_minimum_required(VERSION 3.11) # FetchContent added in cmake 3.11 project(app VERSION 0.1.0 LANGUAGES C CXX) # name of executable set(CMAKE_CXX_STANDARD 23) set (CMAKE_CXX_STANDARD_REQUIRED on) # debug-macro include(FetchContent) FetchContent_Declare(debug_macro GIT_REPOSITORY https://github.com/RFoe/debug_macro) FetchContent_MakeAvailable(debug_macro) add_executable(${PROJECT_NAME} main.cpp) # your source files goes here target_link_libraries(${PROJECT_NAME} PRIVATE debug_macro) # make debug_macro.hxx available
int x = 10; std::string name = "debug_macro"; debug_macro(x, name);
struct X { int a = 8; double b = 2.32; }; enum E : unsigned char { RED = 8, BLUE = 122, }; namespace { void test() { int const lval = 8; int&& xval = 8; std::string s{ "hello world" }; int multi_rank_array[][2]{ { 1, 2 }, { 3, 4 }, }; std::tuple tuple{ 1, 2.2, "hello" }; std::queue<int> queue{ { 1, 2, 3 } }; debug_macro(8); debug_macro(lval, (int&&)xval, s); debug_macro("hello", queue); debug_macro(multi_rank_array, tuple, &X::a); debug_macro((&X::a), (1, 2)); debug_macro(X{}, RED, BLUE); } }
// 正确的自定义 formatter 实现 template <> struct std::formatter<YourCustomType> : std::formatter<std::string> { // 注意 const 修饰符 auto format(const YourCustomType& obj, format_context& ctx) const { return std::format_to(ctx.out(), "CustomType(value={})", obj.value); } };
libstdc++ 中,std::formatter 的 format() 方法必须声明为 const。这是由于 __formattable_with 的 requires 表达式强制要求 formatter 对象在格式化过程中保持不变。
debug_macro 支持广泛的类型输出,包括但不限于:
std::stringstd::string_viewcharchar[]const char*
std::vectorstd::liststd::dequestd::arraystd::set/std::multisetstd::map/std::multimap
std::queuestd::priority_queuestd::stack
std::tuplestd::pairaggregate struct
std::is_enum_vstd::is_scoped_enum_v
std::optionalstd::unique_ptr | std::shared_ptr | std::weak_ptr... And more
Task |
Time Required | Assigned To | Current Status | Progress |
|---|---|---|---|---|
| 性能优化 | > 5 days |
未分配 | 进行中 | ✅ 基本完成 |
| 更多平台测试 | > 5 days |
未分配 | 进行中 | ✅ 主平台测试 ⬜️ 部分兼容性 |
| 扩展格式化选项 | > 5 days |
未分配 | 进行中 | ✅ 核心功能 ⬜️ 次要功能 |
| 性能基准测试 | > 5 days |
未分配 | 进行中 | ✅ 初步测试 ⬜️ 部分优化 |
我们欢迎各种形式的贡献!请参见 CONTRIBUTING.md。
- Fork 项目
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开 Pull Request
基于 MIT 许可证发布。详见 LICENSE。
💡 提示: 持续更新中,欢迎 Star 和 Fork!🌟