c++ - 如何使用此 Logger 记录特定类别的数据类型
问题描述
我是 C++ 新手,我正在做一个类项目(CMU 15-445 https://github.com/cmu-db/bustub)和调试。但我不知道如何使用这个记录器。
从logger.h文件中,LOG_INFO是这样定义的:
#ifdef LOG_INFO_ENABLED
#undef LOG_INFO_ENABLED
#endif
#if LOG_LEVEL <= LOG_LEVEL_INFO
#define LOG_INFO_ENABLED
// #pragma message("LOG_INFO was enabled.")
#define LOG_INFO(...) \
OutputLogHeader(__SHORT_FILE__, __LINE__, __FUNCTION__, LOG_LEVEL_INFO); \
::fprintf(LOG_OUTPUT_STREAM, __VA_ARGS__); \
fprintf(LOG_OUTPUT_STREAM, "\n"); \
::fflush(stdout)
#else
#define LOG_INFO(...) ((void)0)
#endif
我知道 LOG_INFO("xxx") 可以打印出 xxx,但我想在generic_key.h中打印一个 <Generic_Key> 类型的值
// NOTE: for test purpose only
// interpret the first 8 bytes as int64_t from data vector
inline int64_t ToString() const { return *reinterpret_cast<int64_t *>(const_cast<char *>(data_)); }
// NOTE: for test purpose only
// interpret the first 8 bytes as int64_t from data vector
friend std::ostream &operator<<(std::ostream &os, const GenericKey &key) {
os << key.ToString();
return os;
}
因此,如果我想打印 The key is inserted.
并且密钥是 GenricKey 的类型。我尝试过类似 LOG_INFO("The key" << key << "is inserted"); 但这是错误的。有什么想法该怎么做?
解决方案
推荐阅读
- laravel - 下一页单击分页后Laravel过滤器重置
- python - 我想为 3-best 分类定义损失函数
- robotframework - 在 Robot Framework 的 Test Teardown 中设置测试消息限制
- python - 如何使用 Python 解密 Cisco 密码类型 7?
- jhipster - 无法从最新的 JHipster 6.5.0 导出 JDL。错误显示“无法读取未定义的属性‘错误’”
- javascript - 将 1 添加到 CSS 选择器
- python-3.x - 使用pickle.load反序列化uwsgi上的自定义对象时出现AttributeError:Can't get attribute 'ModelConfig' on
- php - 当我生成sql脚本而不是直接访问数据库时,如何防止sql注入漏洞?
- javascript - 迭代表格行和单元格并更改特定样式
- java - 用java下载网站时只得到符号