基本Json格式化。

This commit is contained in:
2026-03-29 19:25:59 +08:00
parent 4c8cf346ea
commit 1bc2c2bcbf
10 changed files with 376 additions and 0 deletions

39
util/axc.util.cpp Normal file
View File

@@ -0,0 +1,39 @@
#include "axc.util.h"
#include <boost/nowide/iostream.hpp>
#include <spdlog/common.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <vector>
static std::shared_ptr<spdlog::logger> logger;
bool AxcUtil::initLogger(const std::string& logFile)
{
if (logger) {
return true;
}
try {
auto fileSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("aux_cmd.log", 1024 * 1024 * 5, 3);
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
fileSink->set_pattern("[%Y-%m-%d %H:%M:%S.%e][%l]: %v");
consoleSink->set_pattern("[%H:%M:%S.%e] %^[%l] %v%$");
std::vector<spdlog::sink_ptr> sinks{fileSink, consoleSink};
logger = std::make_shared<spdlog::logger>("aux_cmd", sinks.begin(), sinks.end());
logger->set_level(spdlog::level::debug);
logger->flush_on(spdlog::level::debug);
spdlog::register_logger(logger);
} catch (const spdlog::spdlog_ex& ex) {
boost::nowide::cerr << "Error creating logger: " << ex.what() << std::endl;
return false;
}
return true;
}
std::shared_ptr<spdlog::logger> AxcUtil::getLogger()
{
if (!logger) {
logger = spdlog::get("aux_cmd");
}
return logger;
}

19
util/axc.util.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef AXC_UTIL_H
#define AXC_UTIL_H
#include <spdlog/spdlog.h>
#include <string>
struct FormatterArg {
int indent{4};
std::string file;
};
class AxcUtil
{
public:
static bool initLogger(const std::string& logFile);
static std::shared_ptr<spdlog::logger> getLogger();
};
#endif