This commit is contained in:
lenheart
2024-05-24 19:02:09 +08:00
parent 1f2ddbabe5
commit b6d3556286
140 changed files with 769 additions and 31498 deletions

View File

@@ -1,6 +1,42 @@
#include "l_squirrel.h"
#include "l_squirrel_register.hpp"
#include "spdlog/spdlog.h"
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <iostream>
#include <ctime>
#include <sstream>
#include <chrono>
static char szGamePathA[256];
void setupLogger()
{
getConfigPath(szGamePathA, sizeof(szGamePathA));
std::string Path = std::string(szGamePathA);
std::string log_filename = "log/dps_log/" + Path.substr(Path.find("cfg") + 4) + "/log_";
char time_buffer[100];
std::time_t now = std::time(nullptr);
std::tm *local_time = std::localtime(&now);
strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d_%H-%M-%S", local_time);
log_filename += std::string(time_buffer) + ".txt";
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::info);
console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v");
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(log_filename, true);
file_sink->set_level(spdlog::level::info);
file_sink->set_pattern("[%Y-%m-%d %H:%M:%S] [%^%l%$] %v");
auto logger = std::make_shared<spdlog::logger>("logger", spdlog::sinks_init_list{console_sink, file_sink});
logger->set_level(spdlog::level::info);
logger->flush_on(spdlog::level::info);
logger->info("欢迎使用Dps插件");
spdlog::register_logger(logger);
spdlog::set_default_logger(logger);
}
// 虚拟机对象
HSQUIRRELVM v;
@@ -163,8 +199,7 @@ void InitSquirrel()
sqstd_register_stringlib(v);
sqstd_seterrorhandlers(v);
// 设置日志格式
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v");
setupLogger();
sq_setprintfunc(v, printfunc, errorfunc); // sets the print function
// 输出版本信息