Conversation
Co-authored-by: shawnfeng0 <23150404+shawnfeng0@users.noreply.github.com>
Co-authored-by: shawnfeng0 <23150404+shawnfeng0@users.noreply.github.com>
ulog_fmt)
|
c++版本的接口不要再使用宏接口,可以参考spdlog的实现 |
CMakeLists.txt
Outdated
| option(ULOG_BUILD_EXAMPLES "Build examples" OFF) | ||
| option(ULOG_BUILD_TESTS "Build tests" OFF) | ||
| option(ULOG_BUILD_TOOLS "Build tools" ON) | ||
| option(ULOG_BUILD_FMT "Build C++ fmt frontend (ulog_fmt target)" ON) |
There was a problem hiding this comment.
已在 2e1a699 中移除 ULOG_BUILD_FMT 选项,ulog_fmt 目标默认直接编译,无需判断。
CMakeLists.txt
Outdated
| include(cmake/zstd.cmake) | ||
| endif () | ||
|
|
||
| if (ULOG_BUILD_FMT OR ULOG_BUILD_TESTS) |
There was a problem hiding this comment.
已在 2e1a699 中移除条件判断,include(cmake/fmt.cmake) 和 ulog_fmt 目标现在无条件编译。
include/ulog/ulog_fmt.h
Outdated
| // Step 3: convenience macros mirroring the LOGGER_* / LOGGER_LOCAL_* set | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| #define LOGGER_FMT_LOCAL_TRACE(logger, ...) \ |
There was a problem hiding this comment.
已在 2e1a699 中完全移除所有宏,改用 Logger 类方法和 ulog::info(...) 等自由函数。
tests/CMakeLists.txt
Outdated
| add_test(ulog_unit_test ulog_unit_test) | ||
|
|
||
| # C++ fmt frontend test | ||
| add_executable(ulog_fmt_test ulog_fmt_test.cc) |
There was a problem hiding this comment.
已在 2e1a699 中将 ulog_fmt_test.cc 合并进 ulog_unit_test 目标(使用 gtest),移除了单独的 ulog_fmt_test 可执行文件和测试条目。
include/ulog/ulog_fmt.h
Outdated
| #else | ||
| auto msg = fmt::format(fmt_str, std::forward<Args>(args)...); | ||
| #endif | ||
| logger_log_with_header(logger, level, file, func, line, true, true, "%s", |
There was a problem hiding this comment.
cpp版本不要使用任何原有c语言版本的接口,以后会逐步淘汰c版本接口
There was a problem hiding this comment.
已在 2e1a699 中完全重写 ulog_fmt.h:Logger 类不再调用任何 C 语言接口(logger_log_with_header、logger_raw 等),时间戳、PID/TID、颜色、等级标记、源码位置等所有格式化逻辑均用 C++ + fmt 独立实现。
cmake/fmt.cmake
Outdated
| target_link_libraries(ulog_fmt_dep INTERFACE fmt::fmt) | ||
| message(STATUS "ulog_fmt: using system {fmt} ${fmt_VERSION}") | ||
| else () | ||
| include(FetchContent) |
There was a problem hiding this comment.
已在 2e1a699 中将 fmt 9.1.0 的头文件拷贝至 third_party/fmt/include/fmt/,cmake/fmt.cmake 优先使用该本地目录(header-only 模式),不再执行下载流程。
…tion, tests with unit tests Co-authored-by: shawnfeng0 <23150404+shawnfeng0@users.noreply.github.com>
已重写为 spdlog 风格的 C++ 接口(commit 2e1a699):
|
Adds a header-only C++ logging frontend that accepts
{}-style format strings (fmt interface) with a spdlog-style class-based API, automatic source location capture without macros, and bundled fmt headers to avoid any network downloads or symbol conflicts.New files
include/ulog/ulog_fmt.h— Header-only C++ frontend innamespace ulog. Provides aLoggerclass withtrace()/debug()/info()/warn()/error()/fatal()/raw()methods, plus free functions using a default global logger. Source location (file, line, function) is captured automatically at the call site via__builtin_FILE()/__builtin_LINE()/__builtin_FUNCTION()default constructor parameters — no macros required. Fully self-contained C++ implementation; does not call any C-API functions (logger_log_with_header,logger_raw, etc.).cmake/fmt.cmake— Uses the fmt headers bundled inthird_party/fmt/(header-only mode,FMT_HEADER_ONLY=1). Falls back to a systemfind_package(fmt)if the bundled directory is absent. No network downloads.third_party/fmt/include/fmt/— fmt 9.1.0 headers bundled directly in the repository.tests/ulog_fmt_test.cc— gtest tests covering all log levels, level filtering, automatic source location capture, format specifiers, raw output, and free functions. Compiled as part of the existingulog_unit_testtarget.Modified files
CMakeLists.txt— RemovedULOG_BUILD_FMToption;ulog_fmtinterface target is always compiled unconditionally.tests/CMakeLists.txt—ulog_fmt_test.ccadded toulog_unit_test(gtest) target; no separate executable.Usage
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.