CMakeTutorialStep1 2.3.12
Loading...
Searching...
No Matches
ScenarioLog.hxx
Go to the documentation of this file.
1#pragma once
2
11
12#ifndef CXX_LOG_DIR
13#define CXX_LOG_DIR "log"
14#endif
15
16// 每个 log 文件最多保留的行数(改这里;重新编译 + cmake .. 后生效)
17// 提示:cmake_configure.log 镜像全部终端 STATUS,完整一次配置约 150+ 行
18#ifndef CXX_LOG_MAX_LINES
19#define CXX_LOG_MAX_LINES 300
20#endif
21
22#include <spdlog/spdlog.h>
23
24#include <string>
25#include <string_view>
26
27namespace scenario_log {
28
30void trim_log_file(const std::string& path);
31
33bool under_lldb();
34
36spdlog::logger& exe_logger();
37
39void log_info(std::string_view msg);
40
42void log_error(std::string_view msg);
43
45void log_sep();
46
48spdlog::logger& gtest_logger();
49
51void gtest_info(std::string_view msg);
52
54template <typename In, typename Out>
55void gtest_case(std::string_view fn, const In& input, const Out& expected, const Out& actual) {
56 gtest_logger().info(" {} input={} expected={} actual={}", fn, input, expected, actual);
57 trim_log_file(std::string(CXX_LOG_DIR) + "/gtest.log");
58}
59
60} // namespace scenario_log
#define CXX_LOG_DIR
Definition ScenarioLog.hxx:13
Definition ScenarioLog.cxx:22
void gtest_case(std::string_view fn, const In &input, const Out &expected, const Out &actual)
终端 / gtest.log:记录函数名、输入、预期、实际
Definition ScenarioLog.hxx:55
bool under_lldb()
CXX_LLDB 非空且非 "0",或 macOS 上进程被 tracer 附加
Definition ScenarioLog.cxx:51
void trim_log_file(const std::string &path)
读入全文后只保留末尾 CXX_LOG_MAX_LINES 行,防止 log 无限增长
Definition ScenarioLog.cxx:30
spdlog::logger & exe_logger()
懒初始化:LLDB 下写 lldb_debug.log,否则 exe.log
Definition ScenarioLog.cxx:67
spdlog::logger & gtest_logger()
GTest 专用 logger,文件名固定 gtest.log.
Definition ScenarioLog.cxx:102
void log_error(std::string_view msg)
写 ERROR 级日志并触发裁剪
Definition ScenarioLog.cxx:91
void log_info(std::string_view msg)
写 INFO 级日志并触发裁剪
Definition ScenarioLog.cxx:85
void log_sep()
输出分隔线(经 log_info)
Definition ScenarioLog.cxx:97
void gtest_info(std::string_view msg)
GTest 用 INFO 日志并裁剪 gtest.log.
Definition ScenarioLog.cxx:118