Skip to content

Commit

Permalink
日志模块和创建文件夹部分添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
WZH23 committed Dec 4, 2024
1 parent b79d6d9 commit d50d8d1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/buried_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@ void Buried::InitWorkPath_(const std::string& work_dir) {
std::filesystem::create_directories(_work_dir);
}

work_path_ = _work_dir / "buried";
/*
windows:
传参:D:\\projects\\BuriedPoint
结果:D:\\projects\\BuriedPoint\\buried
linux
传参:/usr/lib
结果:/usr/lib/buried
*/
work_path_ = _work_dir / "buried";//文件路径的拼接
if (!std::filesystem::exists(work_path_)) {
std::filesystem::create_directories(work_path_);
}
}

void Buried::InitLogger_() {
//sinks:控制日志写入的目的地,写入控制台
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();

//写入到文件
std::filesystem::path _log_dir = work_path_ / "buried.log";
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(
_log_dir.string(), true);
Expand All @@ -31,6 +41,12 @@ void Buried::InitLogger_() {
new spdlog::logger("buried_sink", {console_sink, file_sink}));

// ref: https://github.com/gabime/spdlog/wiki/3.-Custom-formatting
//%c:Date and time representation 日期和时间表示
//%s:Basename of the source file 源文件的名称
//%#:Source line 日志在文件中的行号
//%l:The log level of the message 消息的日志级别
//%v:The actual text to log
//[]
logger_->set_pattern("[%c] [%s:%#] [%l] %v");
logger_->set_level(spdlog::level::trace);
}
Expand All @@ -43,6 +59,7 @@ Buried::Buried(const std::string& work_dir) {
InitLogger_();

SPDLOG_LOGGER_INFO(Logger(), "Buried init success");
//SPDLOG_LOGGER_ERROR(Logger(), "err");
}

Buried::~Buried() {}
Expand Down

0 comments on commit d50d8d1

Please sign in to comment.