feat(liblogc): 统一集中式日志客户端库 + 全量迁移

新增:
- liblogc/: C++ 统一日志库 (libus_logc.so),支持 set_endpoint/set_service_name/set_level
- pymsg/pymsg/logc.py: Python 统一日志模块,基于 AsyncRpcQueue

C++ 迁移 (删除 6 份本地 LogC.hpp 副本):
- ca, gateway: <us/LogC.hpp> + set_service_name
- captcha2, confs2, smtp3: using qing::LogC + set_service_name
- core: ConfsLogC → qing::LogC (ConfsTask.cpp)
- 所有 Makefile 添加 -lus_logc

Python 迁移 (6 个 log_client.py → 4 行薄包装):
- smtp, redirect80, confs, captcha, dnfs, static
- 全部委托到 pymsg.logc.LogClient

Go (waf): 保持现状,自成体系
This commit is contained in:
qing committed 2026-08-10 04:51:43 +00:00
1 parent 01ae877673
commit aa3741b861
32 files changed
+608 -2129

No files matched your search

+9 -8
View File
@@ -31,12 +31,12 @@
#include <vector>
#include "main/ConfsTask.hh"
#include "main/ConfsLogC.hpp"
#include <us/LogC.hpp>
namespace json = boost::json;
namespace fs = std::filesystem;
using qing::confs::ConfsLogC;
using qing::LogC;
namespace qing {
@@ -386,6 +386,7 @@ ConfsTask::ConfsTask(std::string addr_, int port_, int workers_, std::string con
: addr(std::move(addr_)), port(port_), workers(workers_),
started_at(std::chrono::steady_clock::now())
{
LogC::instance().set_service_name("confs-log");
store = std::make_unique<ConfigStore>(config_dir);
this->th = std::make_unique<Thread>();
init_thread();
@@ -423,12 +424,12 @@ void ConfsTask::init_thread() {
this->server = std::make_unique<pmc::net::RpcServer> (addr, port,
pmc::net::MsgServerConfig{.workers = workers},
[](const std::string& route, const std::exception& e) {
ConfsLogC::instance().error("confs", "路由 " + route + " 处理异常: " + e.what());
LogC::instance().error("confs", "路由 " + route + " 处理异常: " + e.what());
});
register_routes(*this->server);
th.run();
ConfsLogC::instance().info("confs", "开始监听 tcp://" + addr + ":"
LogC::instance().info("confs", "开始监听 tcp://" + addr + ":"
+ std::to_string(port));
this->server->start(); /* 堵死线程,等待 stop() 解除 */
});
@@ -482,13 +483,13 @@ void ConfsTask::register_routes(pmc::net::RpcServer& rpc) {
auto val = extract_ini_key(entry.content, key);
if (!val)
throw KeyNotFound("键不存在: " + name + " -> " + key);
ConfsLogC::instance().info("confs", "分发配置键 " + name + " -> " + key);
LogC::instance().info("confs", "分发配置键 " + name + " -> " + key);
return json::object{{"name", name}, {"key", key}, {"value", *val}};
}
if (ext == ".json") {
auto val = extract_json_key(entry.content, key);
ConfsLogC::instance().info("confs", "分发配置键 " + name + " -> " + key);
LogC::instance().info("confs", "分发配置键 " + name + " -> " + key);
return json::object{{"name", name}, {"key", key}, {"value", val}};
}
@@ -519,7 +520,7 @@ void ConfsTask::register_routes(pmc::net::RpcServer& rpc) {
// 省略 name 或 null → 清空全部缓存
if (it == req.end() || it->value().is_null()) {
auto names = store->reload(nullptr);
ConfsLogC::instance().info("confs", "清空配置缓存(" + std::to_string(names.size()) + " 项)");
LogC::instance().info("confs", "清空配置缓存(" + std::to_string(names.size()) + " 项)");
json::array arr;
for (const auto& n : names) arr.push_back(json::value(n));
return json::object{{"reloaded", arr}};
@@ -534,7 +535,7 @@ void ConfsTask::register_routes(pmc::net::RpcServer& rpc) {
throw ConfigError("name 字段不能为空(要清空全部缓存请省略 name 字段)");
auto names = store->reload(&name);
ConfsLogC::instance().info("confs", "重载配置 " + names[0]);
LogC::instance().info("confs", "重载配置 " + names[0]);
json::array arr;
for (const auto& n : names) arr.push_back(json::value(n));
return json::object{{"reloaded", arr}};