自定义内存分配池
This commit is contained in:
@@ -19,6 +19,7 @@ std::string handle_fileName(std::string_view utf8_str) {
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
@@ -121,6 +122,34 @@ void pure_log(std::string_view pure_path, std::string_view info,
|
||||
logger->flush();
|
||||
}
|
||||
}
|
||||
void csv_log(std::string_view pure_path, std::string_view header, std::string_view line) {
|
||||
auto path = Psc::get_abs_path(pure_path);
|
||||
static std::map<std::string, std::shared_ptr<spdlog::logger>> file_logger_map;
|
||||
static std::mutex mtx;
|
||||
static std::once_flag pool_flag;
|
||||
std::call_once(pool_flag, []() {
|
||||
if (!spdlog::thread_pool())
|
||||
spdlog::init_thread_pool(1024 * 1024, 1);
|
||||
spdlog::flush_every(std::chrono::seconds(1));
|
||||
});
|
||||
std::shared_ptr<spdlog::logger> logger;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
auto iter = file_logger_map.find(path);
|
||||
if (iter == file_logger_map.end()) {
|
||||
Psc::create_file_if_not_exists(path);
|
||||
std::string platform_path = Psc::utf8_2_platform(path);
|
||||
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(platform_path, true);
|
||||
auto created = std::make_shared<spdlog::async_logger>(platform_path, sink, spdlog::thread_pool(), spdlog::async_overflow_policy::overrun_oldest);
|
||||
auto formatter = std::make_unique<spdlog::pattern_formatter>("%v", spdlog::pattern_time_type::local, "\n", spdlog::pattern_formatter::custom_flags());
|
||||
created->set_formatter(std::move(formatter));
|
||||
created->info(header);
|
||||
iter = file_logger_map.insert({path, created}).first;
|
||||
}
|
||||
logger = iter->second;
|
||||
}
|
||||
logger->info(line);
|
||||
}
|
||||
Log_Type& Log_Type::append(std::string_view key) {
|
||||
list.push_back(std::string(key));
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user